calling __dopPostback from javascript where target control is an ASP.Net custom control
I need to pop up a jquery dialog as confirmation before a submit happens. I don't want the dialog to always pop u开发者_StackOverflow中文版p, that depends upon the setting of a dropdown.
The submitting control (which I can't change by the way) is a custom control with a save and a cancel button and handlers for the save and cancel buttons.
So when the user has selected a particular item from the drop down I hook up the click event (on the clientside) of the save button (that has been rendered by the custom control) to a js function using jQuery, that calls my showDialog() function and then returns false (to prevent the postback).
I now need, when the user clicks the yes button on the dialog, to call __doPostBack to get the SaveButtons serverside events to fire and to get the serverrside validation to run.
I've got
eval($("#<%= hdnBtnPostback.ClientID %>").val());
in the handler for the Yes button on the dialog.
The hdnPostBack field contains the result of:
Page.ClientScript.GetPostBackEventReference(mySaveCancelCustomControl, String.Empty)
Unsuprisingly this isn't working. The mySaveCancelCustomControl is the custom control mentioned above and it has two buttons that are rendered with two event handlers so the GetPostBackEventReference is doomed to fail.
Any ideas what I should do?
You can make the button a dialog button and put a asp.net button on the page with the ID of HiddenButton and wrap it in a div with a style of display:none;
so the button is not visible. (Must not be Visible="false" so the button is rendered)
In the dialog javascript add a button that has the effect of clicking the hidden button
jQuery("#dialog").dialog({
buttons: {
'ButtonText': function() {
__doPostBack('<%# HiddenButton.ClientID %>', '')
jQuery(this).dialog('close');
}
}
});
and add a asp click handler to the hidden button
<div style="display:none;">
<asp:Button ID="HiddenButton" OnClick="HiddenButton_Click" ></Button>
<div>
Click event (HiddenButton_Click) on the serverside will fire when the dialog button is clicked
Hope this helps I use this pattern all the time
ps If ClientID does not work in the __doPostback() call user UniqueID I cant remember which it is.
When you are wiring up your new click on the client side, could you save the current click method into a temporary variable and then call the temporary variable from your Yes button?
精彩评论