javascript error in postback on 1.1

Posted by Paul Farrow - Under: Software

Normal story, deploy code and what you think is live isnt actually live.  In this case I am talking about the 1.1 Service pack 1.

And low and behold get a lovely javascript error when you have added controls to pages etc etc.

So after much digging around I found a solution to the problem (that is rather than deploying the service pack due to restrictions on the live server), which works lovely.  The solution …

You can override the render method in your pages or base classes depending on what your doing, like so

// Override the render method for all those machines
// without 1.1 service pack 1

protected override voidRender(HtmlTextWriter writer)
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
string html = stringBuilder.ToString();
int start = html.IndexOf(”

int end = html.IndexOf(“\””, start);
string formID = html.Substring(start, end – start);
string replace = formID.Replace(“:”, “_”);
html = html.Replace(“document.” + formID, “document.” + replace);

This will only work if you have a form tag in your page, I guess we could adapt it so if the page doesnt have a form then dont do the replace, ie no postback needed.