By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
"Ryan" <ry************@kp.org> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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

Nov 19 '05 #2

P: n/a
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

Chris Botha wrote:
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.
"Ryan" <ry************@kp.org> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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


Nov 19 '05 #3

P: n/a
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

Chris Botha wrote:
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.
"Ryan" <ry************@kp.org> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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


Nov 19 '05 #4

P: n/a
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.
"Ryan" <ry************@kp.org> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Chris Botha wrote:
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.
"Ryan" <ry************@kp.org> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
> 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
>

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.