Onclick Event won't fire for an HTML button with runat="server"

R

Ryan

Hello,

I have a standard HTML button on an aspx web form that I have set to
runat server. The button is named reset1 and its tag is as follows:

<INPUT id="btnReset1" style="WIDTH: 60px; HEIGHT: 24px" type="reset"
value="Reset" name="btnReset1" runat="server">

Using Interdev I then double click the button in design view and in the
code behind page (aspx.vb) have the following:

Private Sub btnReset1_ServerClick(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnReset1.ServerClick
Response.Write("<SCRIPT LANGUAGE='javascript'>")
Response.Write("alert('hi')")
Response.Write("</SCRIPT>")
End Sub

All my <ASP:OBJECTS> run fine, but NOTHING happens when I click this
one button. I have tried adding different onclick events to call the
code behind without success. What do I need to do to get this button
to fire the server-side code?

Thanks,
Ryan
 
C

Chris Botha

Do you want to reset the form and post back?
In this case change the type of the button to "button" instead of "reset".
Then in HTML view of the page, do the following:
Add an onclick event for the Java Script, so it should look something like
this
<INPUT onclick="DoTheReset();" id="Reset1" ......
Note the semi-colon after the function name, because it is runat server, MS
will add more Java script for postback, else you will get an error.
Then add Java script right to the end of the page
function DoTheReset() {
Form1.reset();
}

Your script will run first, then the MS script to do the postback.
 
R

Ryan

Hi Chris,

Yes, this is what I am looking to do. The problem with the different
approaches I have tried so far is that I am trying to get to a
completely clean page...pre-databinding. I have tried clearing the all
the fields using javascript then clearing the view state using an ASP
Button. My data comes back as if I had never cleared it. It seems to
remember when it reposts. (I just called ViewState.clear). Will the
method below work to restore a blank slate page (pre-databind)...I wish
they had a data.unbind!!!

Thanks,
Ryan
 
R

Ryan

Hi Chris,

Yes, this is what I am looking to do. The problem with the different
approaches I have tried so far is that I am trying to get to a
completely clean page...pre-databinding. I have tried clearing the all
the fields using javascript then clearing the view state using an ASP
Button. My data comes back as if I had never cleared it. It seems to
remember when it reposts. (I just called ViewState.clear). Will the
method below work to restore a blank slate page (pre-databind)...I wish
they had a data.unbind!!!

By the way, I have found that if I redirect myself back I have no
problem, but this seems kludgy...

Thanks,
Ryan
 
C

Chris Botha

Redirect back to the page is a good idea then, it is simple and if it works
for you it is less kludgy than Java script, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top