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

StackOverflow https://stackoverflow.com/questions/12755374

  •  05-07-2021
  •  | 
  •  

Question

I have a page some 2 ASP Tabs and with an UpdatePanel on the first tab. 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. 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? How do I get it to perform a function of my own design, instead of posting?

Thank you,

Was it helpful?

Solution

You can add javascript click event and stop it to do post back by returning 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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top