简体   繁体   中英

Using asp.net ajax method to stop the page from refreshing after a buttonclick in VS2012

Using VS2012, I have a button that gets clicked to return some info to a textbox on the screen. I also have a label, label3, that is set to the following

protected void Page_Load(object sender, EventArgs e)
    {

        Label3.Text = ("THE FIRST RUN RECORDED AT" + DateTime.Now.ToString(" hh:mm:ss tt"));

    }

Now naturally every time I press the button to return my information in the other part of the c#/web form it refreshes the hh:mm:ss to the current time.

My question is - Where I can call my function to stop my label from refreshing when the button is clicked?

The button calls this

protected void Button1_Click(object sender, EventArgs e)
    {
        WebService1 ws1 = new WebService1();
        Label2.Text = ws1.codes(TextBox1.Text);
    }

It just returns a string dependent on input.

Place Label3 out of UpdatePanel and other controls inside UpdatePanel.
In aspx :

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click2" Text="OK" />
        <br />
        <asp:Label ID="Label2" runat="server"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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