Saturday, March 24, 2012

UpdatePanel and __doPostBack

My app loads one of several dynamically generated reports, implemented as user Controls, (*.ascx files) into an Update Panel. I am trying to do this without a page postback. However, client side code needs to validate several things before issuing the asynchronous request. In IE, I was using an ASP.Net custom Validator control hooked to a client side script
(GenerateReport(sender, e) {...}
to control this, (usinge.valid = true/false; to control whether the asynchronous request to update the content in the UpdatePanel was sent or not, but I have discovered that Firefox does not implement ASP.Net Validators properly.

So now I am trying to accomplish the same functionality simply using a client side script that calls __doPostBack(eventTarget, eventArgs);
But I can't seem to get the __doPostBack to call the Microsoft AJAX asynhcronous call, instead of doing a complete page postback.

How do I do that? Or is there a better way to do this.

Another option I have considered is to put the user control into a web service, that somehow just returns the innerHTML of the user5 control rendering process, but I can;t seem to figure that out either..

ideas anyone?

I've been fighting the same problem the last couple of days. Here is what I just finally came up with...

I write the __doPostBack on the server side and insert it into an onClick event on a control.

String sOnClick

="__doPostBack('" +this.UpdatePanel1.UniqueID +"','eventarg1$eventarg2');"; // the Update Panel's UniqueID will call the asynchronous request and pass the event argument string

e.Row.Attributes.Add("onClick",sOnClick); // I'm adding this to a gridview, I'm guessing this will work elsewhere too.

Then in the Page_Load I parse the event arguments and call the appropriate function

StringsEventArguments =this.Request.Params["__EVENTARGUMENT"];if(sEventArguments !=null)

{

Int32iDelimiter =sEventArguments.IndexOf('$');

StringsArgument =sEventArguments.Substring(iDelimiter + 1);

if (sEventArguments.StartsWith("eventarg1")) EventFunction(sArgument);

}

I hope this helps.

G


You canuse __doPostBack() to refresh an UpdatePanel, if you target the UpdatePanel itself.

No comments:

Post a Comment