469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

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

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
4 6111
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
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
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
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.

Similar topics

3 posts views Thread by Libra Blue | last post: by
2 posts views Thread by Lubomir | last post: by
2 posts views Thread by Miguel Dias Moura | last post: by
6 posts views Thread by Martin Eyles | last post: by
reply views Thread by uto | last post: by
19 posts views Thread by Scott M. | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.