Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Buttons and

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TarTar - 07 Aug 2007 20:11 GMT
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 - 07 Aug 2007 21:53 GMT
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.

>I have two buttons on my ASP.NET 2.0 form:
>
[quoted text clipped - 19 lines]
> Thanks,
> Leszek
TarTar - 07 Aug 2007 22:04 GMT
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

> That's how Validation is done.
> When button has CausesValidation=true then ASP.NET automatically generates
[quoted text clipped - 29 lines]
>> Thanks,
>> Leszek

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.