5

How can i use HTML button like an ASP.NET Button?

1
  • 1
    like a asp.net button? with code-behind you mean? Commented Jan 16, 2012 at 23:52

3 Answers 3

18

Html tags attributed with runat="server" are called HtmlControls and you need to handle ServerClick event.

Markup

<button id="button1" runat="server" onserverclick="doIt" >Submit</button>

Code behind

protected void doIt(object sender, EventArgs e)
 {
   Response.Write("Hello World!!!");
 }
Sign up to request clarification or add additional context in comments.

Comments

7

Add runat=server to the HTML definition as so:

<button id="btnserver" runat="server" .../>

That will make it a server control

2 Comments

like this: <input type="button" runat="server" class="button" name="btnRegister" onclick="btnRegister_Click"/> ????
protected void btnRegister_Click(object sender, EventArgs e) { btn.Text = "yes"; }
1

Basically you can turn html elements in to asp.net by adding runat="server" attribute.In that way you can use html button as asp.net in following way:

<button id="btnOne" runat="server"></button>

Now if you have click events for your button, you can use the onserverclick attribute:

<button id="btnOne" runat="server" onserverclick="btnOne_Click"></button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.