简体   繁体   English

如何动态创建一个不会在UpdatePanel内引起回发的ASP:Button?

[英]How can I dynamically create an ASP:Button that causes no postback inside an UpdatePanel?

I have a page some 2 ASP Tabs and with an UpdatePanel on the first tab. 我的页面上有2个ASP选项卡,第一个选项卡上带有UpdatePanel。 Inside the update panel (on page_load), I dynamically create a table that contains rows with cells for an image, some text, and an ASP:Button. 在更新面板中(在page_load上),我动态创建一个表,该表包含带有单元格的行,这些单元格包含图像,一些文本和一个ASP:Button。 I'd like the button, when clicked to switch tabs from the first to the second. 单击按钮以将选项卡从第一个切换到第二个时,我想要按钮。 Instead, all it does is refresh the updatepanel it resides in. How can I stop it from behaving that way? 相反,它所做的只是刷新它所驻留的updatepanel。如何阻止这种行为? How do I get it to perform a function of my own design, instead of posting? 我如何获得它来执行自己设计的功能,而不是发布?

Thank you, 谢谢,

You can add javascript click event and stop it to do post back by returning false; 您可以添加javascript click事件,并通过返回false来使其停止发回;

In Code behind, where you add button dynamically. 在后面的代码中,您可以在其中动态添加按钮。

btnChangeTab.Attributes.Add("onclick", "return YourJavascriptFunction();");

In Client side. 在客户端。

<script type="text/javascript">

 function YourJavascriptFunction()
 {
      //Your javascript code here 
      return false; //the will stop from postback
 }

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM