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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan

    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_Serve rClick(ByVal sender As System.Object, ByVal
    e As System.EventArg s) Handles btnReset1.Serve rClick
    Response.Write( "<SCRIPT LANGUAGE='javas cript'>")
    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

    #2
    Re: Onclick Event won't fire for an HTML button with runat=&quot;ser ver&quot;

    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="DoTheR eset();" 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" <ryan.d.rembaum @kp.org> wrote in message
    news:1131397949 .343239.234970@ g49g2000cwa.goo glegroups.com.. .[color=blue]
    > 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_Serve rClick(ByVal sender As System.Object, ByVal
    > e As System.EventArg s) Handles btnReset1.Serve rClick
    > Response.Write( "<SCRIPT LANGUAGE='javas cript'>")
    > 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
    >[/color]


    Comment

    • Ryan

      #3
      Re: Onclick Event won't fire for an HTML button with runat=&quot;ser ver&quot;

      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:[color=blue]
      > 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="DoTheR eset();" 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" <ryan.d.rembaum @kp.org> wrote in message
      > news:1131397949 .343239.234970@ g49g2000cwa.goo glegroups.com.. .[color=green]
      > > 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_Serve rClick(ByVal sender As System.Object, ByVal
      > > e As System.EventArg s) Handles btnReset1.Serve rClick
      > > Response.Write( "<SCRIPT LANGUAGE='javas cript'>")
      > > 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
      > >[/color][/color]

      Comment

      • Ryan

        #4
        Re: Onclick Event won't fire for an HTML button with runat=&quot;ser ver&quot;

        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:[color=blue]
        > 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="DoTheR eset();" 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" <ryan.d.rembaum @kp.org> wrote in message
        > news:1131397949 .343239.234970@ g49g2000cwa.goo glegroups.com.. .[color=green]
        > > 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_Serve rClick(ByVal sender As System.Object, ByVal
        > > e As System.EventArg s) Handles btnReset1.Serve rClick
        > > Response.Write( "<SCRIPT LANGUAGE='javas cript'>")
        > > 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
        > >[/color][/color]

        Comment

        • Chris Botha

          #5
          Re: Onclick Event won't fire for an HTML button with runat=&quot;ser ver&quot;

          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" <ryan.d.rembaum @kp.org> wrote in message
          news:1131416664 .246355.180690@ g43g2000cwa.goo glegroups.com.. .[color=blue]
          > 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:[color=green]
          >> 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="DoTheR eset();" 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" <ryan.d.rembaum @kp.org> wrote in message
          >> news:1131397949 .343239.234970@ g49g2000cwa.goo glegroups.com.. .[color=darkred]
          >> > 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_Serve rClick(ByVal sender As System.Object, ByVal
          >> > e As System.EventArg s) Handles btnReset1.Serve rClick
          >> > Response.Write( "<SCRIPT LANGUAGE='javas cript'>")
          >> > 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
          >> >[/color][/color]
          >[/color]


          Comment

          Working...