Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to avoid postback on button click event.Here,my requirement is that, first time my page load with some initial values which are set it as from javascript.& I want to preserve these values after button click event fires.

Can you help me asap..

Thanks..
Posted
Comments
bbirajdar 19-Jul-12 11:04am    
Use the HTML input button

Hi,

If I understand what you're saying, you're loosing your values because they're not in the viewstate. You have two choices, either you do a postback and get those values from your form (the one you just posted: Request.Form[]) otherwise you can put an href and make it call a js function.

Hope it helps.
 
Share this answer
 
Hi ran rajendra@patil55,

If you mean like validating a form or something here is something i would like to share, hope this helps.

in the head of your page:
JavaScript
<script type = "text/javascript">
    function validate() {

        var txt = document.getElementById("<%=Textbox1.ClientID%>").value;
        if (txt == "") {
            alert("Please enter your name in the textbox before proceeding.");
        }
        else {
            window.location = "default.aspx";
        }
    }
</script>


and in the button:
ASP.NET
<asp:button id="Button1" runat="server" text="Proceed" onclientclick="validate(); return false" xmlns:asp="#unknown" />

the return false after the function call prevents the postback.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900