问题
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%2frVIKQzKE1L0k4QhIc768w &_ASYNCPOST=true&
Why is not Click event for btnDateRangeCallback hitting???
回答1:
Use the UniqueID instead: __doPostBack('<%=btnDateRangeCallback.UniqueID %>', ...
回答2:
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).
来源:https://stackoverflow.com/questions/6213580/dopostback-not-working-as-expected