|
|
|
start date: Tue, 7 Aug 2007 15:11:14 -0400,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
TarTar
|
|
2
George Ter-Saakov
|
|
3
TarTar
|
Buttons and
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("btnSubmit", "", true,
"", "", 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
Date:Tue, 7 Aug 2007 15:11:14 -0400
Author:
|
Re: Buttons and
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$cS2HHA.600@TK2MSFTNGP05.phx.gbl...
>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("btnSubmit", "", true,
> "", "", 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
>
>
Date:Tue, 7 Aug 2007 16:53:28 -0400
Author:
|
Re: Buttons and
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%23kGUT2HHA.140@TK2MSFTNGP02.phx.gbl...
> 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$cS2HHA.600@TK2MSFTNGP05.phx.gbl...
>>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("btnSubmit", "", true,
>> "", "", 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
>>
>>
>
>
Date:Tue, 7 Aug 2007 17:04:56 -0400
Author:
|
|
|