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

Discussion in 'ASP .Net' started by Ryan, Nov 7, 2005.

  1. Ryan

    Ryan Guest

    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
    Ryan, Nov 7, 2005
    #1
    1. Advertising

  2. Ryan

    Chris Botha Guest

    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" <> wrote in message
    news:...
    > 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
    >
    Chris Botha, Nov 7, 2005
    #2
    1. Advertising

  3. Ryan

    Ryan Guest

    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" <> wrote in message
    > news:...
    > > 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
    > >
    Ryan, Nov 8, 2005
    #3
  4. Ryan

    Ryan Guest

    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" <> wrote in message
    > news:...
    > > 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
    > >
    Ryan, Nov 8, 2005
    #4
  5. Ryan

    Chris Botha Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    >> news:...
    >> > 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
    >> >

    >
    Chris Botha, Nov 8, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,312
  2. -Karl

    OnClick event won't fire

    -Karl, Jul 5, 2007, in forum: ASP .Net
    Replies:
    13
    Views:
    863
    -Karl
    Jul 9, 2007
  3. Stefan

    Button in WebCustomControl don't fire the onclick event, why?

    Stefan, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    215
    Stefan
    Jul 9, 2003
  4. mbs57

    ASP.NET button control OnClick event doesn't fire

    mbs57, Jun 18, 2009, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,394
  5. Replies:
    2
    Views:
    242
Loading...

Share This Page