Showing posts with label ascx. Show all posts
Showing posts with label ascx. Show all posts

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.

UpdatePanel and Dynamic Controls...

Hello all,

I have created a *.ascx (UserControl) which I added in the web form in UpdatePanel dynamically using Page.LoadControl function. The control is rendered fine. But the client side event handlers (that I defined in the javascript of the UserControl) are not rendered. When that event is raised, it raises the "Object Required" javascript exception. It happens because that function (handler) is not rendered. Please give me solution to this problem. Here is the sample

(this is done on server side Page_Load event handler)

WebCombo1.ClientSideEvents.BeforeDropDown =

"WebCombo_BeforeDropDown" + ControlID;

(Now I have defined the handler on the client side as)

function WebCombo_BeforeDropDown<%=ControlID%>(webComboId)

{

.... my code here...

}

Thanks in Advance

Mudassar

The reason it does not work is because innerHTML, which UpdatePanel framework uses on the client side, does not work for embedded script tags in HTML.

If you can register the script blocks using ScriptManager.RegisterClientScriptBlock that will be the best. So instaed of putting them in script Tags generate them in a string and use ScriptManager.RegisterClientScriptBlock.