Last post Jun 03, 2009 12:12 AM by Mobius5150
May 31, 2009 10:24 PM|Mobius5150|LINK
I built a webpage, and i am now taking parts of the page and turning them into user controls.
I need to call a button_click event handler in the server side code. Beforehand, i did it with this command:
__doPostBack("<%= Refresh.ClientID %>;", "");
But now that the (hidden) button is inside a user control, this is no longer working. When i call the above script, the page does a full postback (before, it would do an async postback because the button is inside an updatepanel) and none of the server
side code from the buttons event handler fires.
Could anyone give some suggestions on this?
Jun 01, 2009 01:39 AM|abinashpatra|LINK
You should first update a hidden variable say (hdnButtonClick) and then call __doPostBack("<%= Refresh.ClientID %>;",
In teh page load event catch hold of this hiden variable. If this is set then call the post back of the event like
I hope this helps.
Jun 01, 2009 02:02 AM|sumitd|LINK
Why do you want to call a method of a button which is hidden?
The event is not firing because the button is hidden, so the id of the button control won't be available on the html page.
Right click on the page and check view source, is the hidden button available in the html code?
Jun 02, 2009 12:27 AM|Mobius5150|LINK
I am calling this as it works as a good way to have the page postback asynchronously without having to write any extra code (using a button in an updatepanel).
The Working code from the original page is here:
__doPostBack("<%= Refresh.ClientID %>", "");
The asp.net button control:
<asp:Button Visible="false" ID="Refresh" runat="server" Text="Button" Enabled="false" OnClick="Refresh_Click" />
Again, the above code works perfectly in the original page, but when i put it into a user control, it stops working.
Also, if you use the ASP.NET __doPostBack() function it should fire the buttons event handler even if its disabled (as is my understanding) just as long as you have eventvalidation set to "false" on the page"
Does anyone have any suggestions on this?
Jun 02, 2009 01:08 AM|sumitd|LINK
Refer below extreme, scroll to extreme bottom of the page:
Jun 02, 2009 01:14 AM|Mobius5150|LINK
Thanks for the reply,
Sadly i do not have experts-echange (its just something about having to pay to use a forum)
Could you show me what they suggest?
Jun 02, 2009 01:37 AM|sumitd|LINK
It's very sad to hear that you replied without even opening the site and scrolling it at extreme bottom of the page. I am also not member of expers exchange. If you would have scrolled extreme bottom of the page you could have see the solution.
Jun 02, 2009 01:46 AM|Mobius5150|LINK
To tell you the truth, i did originally open the link and take a look. I scrolled all the way down to the copyright notice (1996-2009 if it matters to you) and i still see no solution. I see the question, and severall links to start a 7 day free trial,
but no solution.
Could you please share with me what you see, as we obviously are not seeing the same things.
Jun 02, 2009 04:17 AM|Allen Chen – MSFT|LINK
If you want to use async postback you can either try triggers:
or put your user control in the UpdatePanel.
Jun 03, 2009 12:12 AM|Mobius5150|LINK
Thanks all for helping.
I found the solution, When you are refrencing server side controls that are inside a user control, you must know the user id of the control inside the root page.
document.getElementById("<%= me.id %>_ServerSideElementName");
__doPostBack("<%= me.id %>$ServerSideElementName", "");
Note the difference between the two commands: Sepcifically the
you must put the controls client side name inside the first parameter.
You may also need to add eventvalidation='false' to the page in the top <% %> parts. (usually line 1) if you are using the __doPostBack() function.
Hope this helps someone else so they dont have to spend as much time as i did on this.