Buttons and

Discussion in 'ASP .Net' started by TarTar, Aug 7, 2007.

  1. TarTar

    TarTar Guest

    I have two buttons on my ASP.NET 2.0 form:

    <asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"
    CausesValidation="true" runat="server"></asp:Button>
    <asp:Button id="btnCancel" Text="Cancel" OnClick="btnCancel_Click"
    CausesValidation="false" runat="server"></asp:Button>

    The following HTML code is generated:

    <input type="submit" name="btnSubmit" value="Update"
    onclick="javascript:WebForm_DoPostBackWithOptions(new
    WebForm_PostBackOptions(&quot;btnSubmit&quot;, &quot;&quot;, true,
    &quot;&quot;, &quot;&quot;, false, false))" id="btnSubmit" />
    <input type="submit" name="btnCancel" value="Cancel" id="btnCancel" />

    Why the onclick event handler is called for the first button that has
    CausesValidation="true", but not for the other one that has
    CausesValidation="false"? The CausesValidation property should not have any
    influence on the event handler. Yet when I set CausesValidation="true" for
    the second button - the onclick event is called.

    Thanks,
    Leszek
     
    TarTar, Aug 7, 2007
    #1
    1. Advertising

  2. That's how Validation is done.
    When button has CausesValidation=true then ASP.NET automatically generates
    code to run JavaScript validation before submitting the form.

    Obviously when CausesValidation=false the button becomes regular submit
    button. Since no JavaScript needs to be run.

    George.



    "TarTar" <> wrote in message
    news:eJDJ$...
    >I have two buttons on my ASP.NET 2.0 form:
    >
    > <asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"
    > CausesValidation="true" runat="server"></asp:Button>
    > <asp:Button id="btnCancel" Text="Cancel" OnClick="btnCancel_Click"
    > CausesValidation="false" runat="server"></asp:Button>
    >
    > The following HTML code is generated:
    >
    > <input type="submit" name="btnSubmit" value="Update"
    > onclick="javascript:WebForm_DoPostBackWithOptions(new
    > WebForm_PostBackOptions(&quot;btnSubmit&quot;, &quot;&quot;, true,
    > &quot;&quot;, &quot;&quot;, false, false))" id="btnSubmit" />
    > <input type="submit" name="btnCancel" value="Cancel" id="btnCancel" />
    >
    > Why the onclick event handler is called for the first button that has
    > CausesValidation="true", but not for the other one that has
    > CausesValidation="false"? The CausesValidation property should not have
    > any influence on the event handler. Yet when I set CausesValidation="true"
    > for the second button - the onclick event is called.
    >
    > Thanks,
    > Leszek
    >
    >
     
    George Ter-Saakov, Aug 7, 2007
    #2
    1. Advertising

  3. TarTar

    TarTar Guest

    Thanks.

    The problem was that the button did not generate postbacks unless
    CausesValidation was set to true.
    It was a very weird problem indeed. I have solved it. It turned out I had to
    use the following tags to include java script code:
    <script type="text/javascript" src="grid.js"></script>
    instead of
    <script language="javascript" src="grid.js" />

    Strange - but now the form is working like a charm.

    Leszek

    "George Ter-Saakov" <> wrote in message
    news:eD%...
    > That's how Validation is done.
    > When button has CausesValidation=true then ASP.NET automatically generates
    > code to run JavaScript validation before submitting the form.
    >
    > Obviously when CausesValidation=false the button becomes regular submit
    > button. Since no JavaScript needs to be run.
    >
    > George.
    >
    >
    >
    > "TarTar" <> wrote in message
    > news:eJDJ$...
    >>I have two buttons on my ASP.NET 2.0 form:
    >>
    >> <asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"
    >> CausesValidation="true" runat="server"></asp:Button>
    >> <asp:Button id="btnCancel" Text="Cancel" OnClick="btnCancel_Click"
    >> CausesValidation="false" runat="server"></asp:Button>
    >>
    >> The following HTML code is generated:
    >>
    >> <input type="submit" name="btnSubmit" value="Update"
    >> onclick="javascript:WebForm_DoPostBackWithOptions(new
    >> WebForm_PostBackOptions(&quot;btnSubmit&quot;, &quot;&quot;, true,
    >> &quot;&quot;, &quot;&quot;, false, false))" id="btnSubmit" />
    >> <input type="submit" name="btnCancel" value="Cancel" id="btnCancel" />
    >>
    >> Why the onclick event handler is called for the first button that has
    >> CausesValidation="true", but not for the other one that has
    >> CausesValidation="false"? The CausesValidation property should not have
    >> any influence on the event handler. Yet when I set
    >> CausesValidation="true" for the second button - the onclick event is
    >> called.
    >>
    >> Thanks,
    >> Leszek
    >>
    >>

    >
    >
     
    TarTar, Aug 7, 2007
    #3
    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. Roger
    Replies:
    1
    Views:
    661
    GreggTB
    May 20, 2005
  2. =?Utf-8?B?QmVu?=

    Image Buttons/Buttons not responding

    =?Utf-8?B?QmVu?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    475
    Teemu Keiski
    Jul 6, 2005
  3. Jeremy Jones

    Datagrid Nav buttons and numeric buttons

    Jeremy Jones, Mar 21, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    641
    Masudur
    Mar 22, 2007
  4. Jonathan N. Little
    Replies:
    3
    Views:
    545
    Andy Dingley
    Apr 2, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    328
    David Mark
    Oct 15, 2007
Loading...

Share This Page