Buttons and

T

TarTar

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
 
G

George Ter-Saakov

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.
 
T

TarTar

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top