Scenario 1 (That Works)
This is a POC i created.
I have a script manager, a html textbox, an ASP.NET button, an updatepanel with async trigger set for Click event of above mentioned button. For html textbox i have, onkeyup='__doPostBack('<%=ASPBUTTON.ClientID%>','')
. AND IT WORKS, the Click event of button is hit, and updatepanel is updated asynchronously.
Scenario 2 (It's not working) The only difference with my actual codebase is that i have a JQUERY FILAMENTGROUP datetimepicker whose onchange event is being used instead of html textbox's onchange. Further, here my page uses a master page. Now, my problem is that when onchange event for datetimepicker fires, the request goes server side, but BUTTON click event is not getting fired.
Some more details, I want to update the updatepanel automatically on datetimepicker selection. So, the button would be actually hidden through css (display:none).
Button id - btnDateRangeCallback
Datetimepicker Textbox (non ASP control) - dateRange
onChange: function() {__doPostBack('<%=btnDateRangeCallback.ClientID%>', $('#dateRange').val());}
[Please remember i said it works in case of my simplistic POC, while in my actual codebase i am using a masterpage to inherit from, and so all these controls are placed in a contentplaceholder. Furthermore, postback is happening, and i can see _EVENTTARGET and _EVENTARGUMENT being sent correctly if i break at Page_Load]
Please help.
To put it more simply, After postback, when i break at Page_Load, i see the Request.Form contents as, ctl00%24ContentPlaceHolder1%24SMgr1=ctl00%24ContentPlaceHolder1%24SMgr1%7cctl00_ContentPlaceHolder1_btnDateRangeCallback &__EVENTTARGET=ctl00_ContentPlaceHolder1_btnDateRangeCallback &_EVENTARGUMENT=5%2f3%2f2011+-+6%2f2%2f2011 &_VIEWSTATE=%2fwEPDwULLTE3NDY5NDIwMDRkZIuTqMNNsFHlRYhjpKaUCaCXj42h &_EVENTVALIDATION=%2fwEWAgLBx52kBALP6Ln6DdkkwE%2开发者_如何学编程frVIKQzKE1L0k4QhIc768w &_ASYNCPOST=true&
Why is not Click event for btnDateRangeCallback hitting???
Use the UniqueID instead: __doPostBack('<%=btnDateRangeCallback.UniqueID %>', ...
Change you code to this:
setTimeout(function () { __doPostBack('btnSave', '') }, 500);
Use "btnSave Id". It will work in all browsers.
Why not just click the button?
onchange="$('#<%= ASPBUTTON.ClientID %>').click()"
(Ideally, don't use inline event handlers either...)
If that's no good for you, you could work around it using __EVENTTARGET
and __EVENTARGUMENT
(see this article for a guide).
The reason why it's not working is because it is in a content place holder.
The first parameter of __doPostBack
is used server side, client side it can be anything. So __doPostBack
is called and submits as desired, but on the server, the first parameter's value is used to find the control that will handle the events. It is used to find the control with the matching UniqueId.
When not in a NamingContainer, UniqueID and ClientID are the same, inside a NamingContainer the ClientId is constructed using underscores (_) and the UniqueId is constructed using dollar signs ($).
Since the value that the server receives in this case doesn't allow it to find a control, it doesn't know what event to fire, and so doesn't fire any, despite registering as a post back and appearing to having an "__EVENTTARGET" that would allow it to find the control.
ClientId will SOMETIMES work when NOT on a MasterPage, in particular it will work just so long as the control is not inside a NamingContainer
. The reason why it won't ever work inside a master page, is that the master page always has a naming container.
精彩评论