开发者

Cause PostBack and Call Event Fired By Server-Side Button (ASP.Net Button)

I have yet another strange need. I have a jQuery dialog that has a dynamic button (

My Button that will be "fired":

<asp:Button ID="RenewSubscriptionButton" runat="server" Visible="false" />

My Hidden input with the postback val:

<input type="hidden" id="RenewSubscriptionPostBackValue" runat="server" />

In my page_load:

Me.RenewSubscriptionPostBackValue.Value = _
       Me.Parent.Page.ClientScript.GetPostBackEventReference _
      (Me.RenewSubscriptionButton, String.Empty)

AddHandler Me.RenewSubscriptionButton.Click, AddressOf RenewSubscription

In my Asp.net control I have a js function that is called and evaluates the __doPostBack that is generated:

$('#mgrSubPanel').dialog('destroy');
// cause postback and have it run the workflow...
eval($("#<%= RenewSubscriptionPostBackValue.ClientID %>").val());

It causes postback but doesn't call my function RenewSubscription that's in my code behind. Not sure if the addressi开发者_Go百科ng is failing or what but maybe one of you can see my fault and correct me...

Thanks in advance...


What happens when you add this PostBackEventReference script to a simple "onlick"? That is generally how I use it... your syntax here had me mystified for a minute there. :| (I'm not really used to jQuery though)

Also, when you say "dynamic button" what exactly do you mean?


You can simplify the code quite a bit by just clicking the button via jQuery, like this:

$('#mgrSubPanel').dialog('destroy');
$("#<%=RenewSubscriptionButton.ClientID %>").click();

This will be as if the user clicked the button directly, no need for the extra <input> or the GetPostBackEventReference code, just keep the handler for the button itself (AddHandler Me...) and you're all set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜