导致服务器端按钮(ASP.Net 按钮)触发的回发和调用事件
我还有另一个奇怪的需求。我有一个 jQuery 对话框,其中有一个动态按钮(
我的按钮将被“触发”:
<asp:Button ID="RenewSubscriptionButton" runat="server" Visible="false" />
带有回发值的隐藏输入:
<input type="hidden" id="RenewSubscriptionPostBackValue" runat="server" />
在我的 page_load 中:
Me.RenewSubscriptionPostBackValue.Value = _
Me.Parent.Page.ClientScript.GetPostBackEventReference _
(Me.RenewSubscriptionButton, String.Empty)
AddHandler Me.RenewSubscriptionButton.Click, AddressOf RenewSubscription
在我的 Asp.net 控件中,我有一个 js 函数,该函数被调用并评估生成的 __doPostBack:
$('#mgrSubPanel').dialog('destroy');
// cause postback and have it run the workflow...
eval($("#<%= RenewSubscriptionPostBackValue.ClientID %>").val());
它会导致回发,但不会调用我的代码中的 RenewSubscription 函数。不确定寻址是否失败或什么,但也许你们中的一个人可以看到我的错误并纠正我...
提前致谢...
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 addressing is failing or what but maybe one of you can see my fault and correct me...
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将此 PostBackEventReference 脚本添加到简单的“onlick”时会发生什么?我通常就是这样使用它的......你的语法让我困惑了一分钟。 :| (虽然我不太习惯 jQuery)
另外,当你说“动态按钮”时,你到底是什么意思?
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?
只需通过 jQuery 单击按钮即可大大简化代码,如下所示:
这就像用户直接单击按钮一样,不需要额外的
或 < code>GetPostBackEventReference 代码,只需保留按钮本身的处理程序 (
AddHandler Me...
) 即可。You can simplify the code quite a bit by just clicking the button via jQuery, like this:
This will be as if the user clicked the button directly, no need for the extra
<input>
or theGetPostBackEventReference
code, just keep the handler for the button itself (AddHandler Me...
) and you're all set.