Usercontrol problem inside updatepanel

I have usercontrol inside the update panel. when I click the button, this user control will be loaded. and the user control itself has any button in it. the problem is that the usercontrol code behind is never executed, and when the usercontrol button is pressed it disappears.

I know this is a common problem. but I did not find a good detailed solution.

I appreciate it.

+6
source share
2 answers

In a user control, simply use the standard HTML button, for example:

<input type="button" id="myButton" onclick="clickTheButton();" value="Click Me"/> 

this will call the javascript method "clickTheButton", which may look like this:

 <script type="text/javascript"> function clickTheButton() { var Sender = window.event.srcElement; //here you can go gather any other values that you need to support the post back var PostBackData = textboxCity.value + "|" + selectState.value if(confirm("are you sure?")) { __doPostBack(Sender.ID, PostBackData) } } </script> 

So now you are going to call the postback from Javascript, identifying the Sender Control arguments and commands. These values ​​are sent with a message back as __EventTarget and __EventArgument and are available from httpRequest when the page loads, for example:

 protected void Page_Load(object sender, EventArgs e) { string controlName = Request.Params.Get("__EVENTTARGET"); string[] commandArguments = Request.Params.Get("__EVENTARGUMENT").split('|') } 

Once you load pages with any values ​​that you have accumulated in commandArguments, you should be able to call any additional methods that you want.

This should make you point in the right direction.

Greetings

CEC

+2
source share

Loading a user control dynamically in the update panel is difficult.

The best solution is to save it in ViewState. Here is a tutorial and sample application .

+1
source share

All Articles