views:

42

answers:

1

Here is what I want to do. Use this HTML line and have the ASP .NET server-side deal with the onclick event.

I don't want to use nor do I want to use an anchor tag which would both allow me to capture the server-side successfully.

I want to use this:

<input type="button" id="submit" name="submit" value="See Your Results" onclick="" />

The onclick attribute for this HTML typically directs the event to a Javascript event handler, which I do not want to use.

This question (http://stackoverflow.com/questions/3445515/input-typebutton-runatserver-wont-work-in-asp-net) details a similar issue, but the end result is to use . I am wondering if it's possible to handle the input tag without resorting to the tag use.

Thanks!

+2  A: 

I believe you need to add runat="server".

Then your onclick will call a server-side method.

This needs to be in a server form tag (see code below).

Here's some information about HTML server controls.

And here's some sample code that you can play with on their webpage:

Declare two HtmlButton controls in an .aspx file (remember to embed the control inside an HtmlForm control). Next, write an event handler that specifies what to happen when a button is clicked.

<script  runat="server">
Sub button1(Source As Object, e As EventArgs)
   p1.InnerHtml="You clicked the blue button!"
End Sub
Sub button2(Source As Object, e As EventArgs)
   p1.InnerHtml="You clicked the pink button!"
End Sub
</script>

<html>
<body>

<form runat="server">
<button id="b1" OnServerClick="button1"
style="background-color:#e6e6fa;
height:25;width:100" runat="server">
Blue button!
</button>
<button id="b2"
OnServerClick="button2"
style="background-color:#fff0f5;
height:25;width:100" runat="server">
Pink button!
</button>
<p id="p1" runat="server" />
</form>

</body>
</html>
DOK
I tried that but I'll try it again. Thanks.
Dan7el
I added some sample code and links + the important bit about putting the control in a server-side form. Good luck!
DOK
I haven't gotten to this yet but I'm wondering, is <button...> the same as <input type="button"....>?
Dan7el
They aren't the same. You might find this helpful: [button> vs. <input type=“button” />. Which to use?](http://stackoverflow.com/questions/469059/button-vs-input-typebutton-which-to-use)
DOK