更新面板和JavaScript哈克重复按钮 [英] Duplicate buttons in Update Panel and JavaScript Hack
问题描述
在引用我的问题,
<一个href=\"http://stackoverflow.com/questions/13531944/page-unload-event-inside-a-update-panel\">Page.Unload一个更新面板内事件
我能够让它工作,但我有两个按钮,这样做部分回发,然后在我的剧本,我可以做我想做的,但我希望它只是一个按钮,而不是两个人的工作,最好的办法是按钮,我想为这个请求工作是图像按钮,而其他按钮只是一个简单的按钮。这是的方式ASP.NET用户控件。
&LT;脚本类型=文/ JavaScript的&GT;
//如果你使用jQuery,您可以在读取DOM加载它们。
$(文件)。就绪(函数(){
变种PRM = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest); }); 功能InitializeRequest(发件人,参数){
} 功能EndRequest(发件人,参数){
//更新后出现的UpdatePanel上运行code。
UnloadMsgBox();
} 功能UnloadMsgBox()
{
警报(信息);
}
&LT; / SCRIPT&GT;
假设你有两种方法,一种名为的button1_Click
和另一个叫 imageButton1_Click
。我们添加一个HiddenField到页面,像这样:
&LT; ASP:HiddenField =服务器ID =hidIsTheButton值=0/&GT;
在我们的的button1_Click
方法:
hidIsTheButton.Value =0;
在我们的 imageButton1_Click
方法:
hidIsTheButton.Value =1;
在这里,的button1_Click
指的是你的标准按钮的事件处理程序和 imageButton1_Click
referes你的的ImageButton
的事件处理程序。
在你的 EndRequest
JavaScript函数:
函数EndRequest(发件人,参数){
//更新后出现的UpdatePanel上运行code。
VAR hidIsTheButton =的document.getElementById('&LT;%= hidIsTheButton.ClientID%GT;');
如果(hidIsTheButton.Value ==1){
UnloadMsgBox();
}
}
In reference to my question,
Page.Unload Event inside a Update Panel
I am able to make it work but I got two buttons that do partial post back and then in my script I can do what I want, but I want it to work for just one button not two of them, best thing is button I want to make this request work for is Image button whereas other button is just a simple button. This is a User Control in ASP.NET by the way.
<script type="text/javascript">
// if you use jQuery, you can load them when dom is read.
$(document).ready(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
});
function InitializeRequest(sender, args) {
}
function EndRequest(sender, args) {
// after update occur on UpdatePanel run the code.
UnloadMsgBox();
}
function UnloadMsgBox()
{
alert("Message");
}
</script>
Say you have two methods, one called button1_Click
and another called imageButton1_Click
. We add a HiddenField to the page like so:
<asp:HiddenField runat="server" ID="hidIsTheButton" value="0" />
In our button1_Click
method:
hidIsTheButton.Value = "0";
In our imageButton1_Click
method:
hidIsTheButton.Value = "1";
Here, button1_Click
refers to your standard buttons event handler and imageButton1_Click
referes to your ImageButton
's event handler.
In your EndRequest
javascript function:
function EndRequest(sender, args) {
// after update occur on UpdatePanel run the code.
var hidIsTheButton = document.getElementById('<%=hidIsTheButton.ClientID%>');
if (hidIsTheButton.Value == "1") {
UnloadMsgBox();
}
}
这篇关于更新面板和JavaScript哈克重复按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!