web analytics

How to Implement a Server Button without Postback in ASP.NET?

Options

codeling 1602 - 6666
@2016-01-06 08:09:01

By default, when clicking on a button of System.Web.UI.WebControls.Button in an ASP.NET page, it will always cause page postbacked.

If you want to a server button without postback triggered after cliking on it, you can do this by follwing the following steps:

1. Add a button of System.Web.UI.HtmlControls.HtmlInputButton to the page

2. Modify the button by adding runat="server":

<INPUT id="clickButton" type="button" value="Button" name="clickButton" runat="server">

3. Bind related Javascript function with the button

 protected System.Web.UI.HtmlControls.HtmlInputButton clickButton;
private void Page_Load(object sender, System.EventArgs e)
{
 ...
 clickButton.Attributes.Add("onclick", "javascriptfunction();");
 clickButton.Value = "Click";
 ...
}

4. Export the corresponding Javascript function in the page or the attached Javascript file.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com