asp.net - ASP button reloading page? -
i have code on aspx page:
<div id="bloc1"> hey </div> <asp:button id="button2" runat="server" text="button" onclick="button2_click" onclientclick="change_page()" /> <input id="button1" type="button" value="button" onclick="change_page()" /> <div id="bloc2" style="display:none"> hey me </div> <script type="text/javascript"> function change_page() { document.getelementbyid("bloc2").style.display = "block"; document.getelementbyid("bloc1").style.display = "none"; } </script>
when click on html button, script works well: bloc1 disappears , bloc2 appears.
when click on asp button, bloc1 disappears , bloc2 appears , bloc2 disappears , bloc1 re-appears (so beginning) if page reloaded.
behind code something:
protected void button2_click(object sender, eventargs e) { this.button2.text = "new button"; }
how can manage html button, behind code function?
ps: don't want use updatepanel , scriptmanager.
you need understand difference between asp.net webforms , how html web page works. <asp:button>
control renders markup <input type="submit">
, regardless of whether or not have onclick
event tied it. means form submitted server upon click, unless stop javascript.
your server doesn't know you've done in javascript showing , hiding things, since things css display
aren't part of post. when page loads again, it's way first time loaded.
you can't have both ways - either post server , new page, or don't. if need execute server code without full post , full load, you'll need ajax - can happen either updatepanels, or proper ajax (for example, jquery ashx handler or webmethod
method).
Comments
Post a Comment