473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ValidatorEnable dying when master pages are involved

Hello,

Here's my scenario:

I have a simple contact form set up where the user can choose how they
wish to be contacted from a list of options presented in a Select box
(DropDownList). Depending on what they choose, a panel will be made
visible with more form fields relating to that option. So, e.g., if
they choose "email" then a panel with a text box for entering the email
address appears.

The issue is this: all visible fields on the form are required, so I
need the ability to turn validators on and off depending on which
option the user chooses. So in the example above, the email address
text box, once visible, needs to be validated. If the user changes
their mind and decides they don't want to be contacted at all, then I
need to turn off whatever validators are involved with the email boxes.
Due to bandwidth limitations for the user base of this app, I cannot
incur a postback in the onchange event of the dropdownlist.

My big problem is that this is a .NET 2.0 app using Master Pages, and
Master Pages seem to kill the ValidatorEnable() function. I've tried
this solution (and a couple of variants) in a page /without/ Master
Pages and it works fine. Showing and Hiding panels with java script
obviously is trivial, but ValidatorEnable only works for turning the
validators on, and not for turning them off. I have pasted in a
lightweight, sample version of my code below for reference. Anyone have
any ideas? I've encountered a couple of similar issues while searching
online, but none have been similar enough for their solutions to work
for me. Any help is greatly appreciated...

Best,
Dan

CODE:
<%@ Page Language="C#" EnableEventValidation="true"
MasterPageFile="~/App_Templates/SomeFolder/Main.master"
AutoEventWireup="true" CodeBehind="SendEmail.aspx.cs"
Inherits="My.Inheritance.Chain.SomeClass" Title="Send Email" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cntBody"
runat="server">
<script type="text/javascript">
function SwitchContactPanels(theValue){
switch(theValue){
case "Email":
document.getElementById("EmailInfo").style.display = "block";

ValidatorEnable(document.getElementById("ctl00_cnt Body_EmailRequired",
true));

ValidatorEnable(document.getElementById("ctl00_cnt Body_CompareEmails",
true));
break;
default:

ValidatorEnable(document.getElementById("ctl00_cnt Body_EmailRequired",
false));

ValidatorEnable(document.getElementById("ctl00_cnt Body_CompareEmails",
false));
document.getElementById("EmailInfo").style.display = "none";
break;
}
}
</script>
<asp:ValidationSummary ID="ErrorSummary" runat="server"
Font-Bold="True" HeaderText="There was a problem with your submission.
Please fix the following and try again:" />
<table id="SendEmailTable" summary="layout table only">
<tr><td class="blackText" colspan="2">Use the following form to submit
feeback. All fields are required.</td></tr>
<tr><td class="labelCell"><label for="Category">Select a
category:</label></td><td class="fieldCell"><asp:DropDownList
runat="server" ID="Category">
<asp:ListItem Value="-1">--Select--</asp:ListItem>
<asp:ListItem>Fake Category 1</asp:ListItem>
<asp:ListItem>Fake Category 2</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="CategoryRequired" runat="server"
ControlToValidate="Category"
Display="Dynamic" ErrorMessage="Select a category."
InitialValue="-1">*</asp:RequiredFieldValidator></td></tr>

<tr><td class="labelCell"><label for="Contact">How may we contact
you?</label></td><td class="fieldCell">
<select runat="server" id="HowToContact"
onchange="SwitchContactPanels(this.value)">
<option value="-1">--Select--</option>
<option>Email</option>
<option>Phone</option>
<option value="Other">Other (specify in message)</option>
<option>Do not contact me</option>
</select>
<asp:RequiredFieldValidator ID="ContactRequired" runat="server"
ControlToValidate="HowToContact"
Display="Dynamic" ErrorMessage="Select a method by which we may
contact you."
InitialValue="-1">*</asp:RequiredFieldValidator></td></tr>
<!--this next row contains the hidden panels to be displayed based on
the "how may we contact you" dropdownlist-->
<tr><td colspan="2">
<div id="EmailInfo" style="display:none;">
<fieldset>
<table>
<tr><td class="labelCell"><label for="EmailAddress">Email
Address:</label></td><td class="fieldCell"><asp:TextBox runat="server"
ID="EmailAddress"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="EmailAddress"
Display="Dynamic" ErrorMessage="Enter your email address."
Enabled="False">*</asp:RequiredFieldValidator></td></tr>
<tr><td class="labelCell"><label for="ConfirmEmail">Confirm
Email:</label></td><td class="fieldCell"><asp:TextBox runat="server"
ID="ConfirmEmail"></asp:TextBox>
<asp:CompareValidator ID="CompareEmails" runat="server"
ControlToCompare="EmailAddress"
ControlToValidate="ConfirmEmail" Enabled="False"
ErrorMessage="Email addresses must match"
Display="Dynamic">*</asp:CompareValidator></td></tr>
</table>
</fieldset>
</div>

</td></tr>

<tr><td colspan="2" class="blackText"><label
for="Message">Message:<asp:RequiredFieldValidator ID="MessageRequired"
runat="server" ControlToValidate="MessageBody"
Display="Dynamic" ErrorMessage="Type a
message.">*</asp:RequiredFieldValidator></label><br /><textarea
cols="65" rows="6" id="MessageBody"
runat="server"></textarea></td></tr>
<tr><td class="labelCell"><asp:Button runat="server" ID="DoSendEmail"
Text="Submit" OnClick="DoSendEmail_Click" /></td><td
class="fieldCell"><button type="reset">Reset</button></td></tr>
</table>
</asp:Content>

Sep 19 '06 #1
0 1999

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: BTHOMASinOHIO | last post by:
I am running through an almost completed Web App and thought I would run it through Netscape for that 5% of users and WOW, Netscape doesn't play nice with the app !!!! Among many formatting...
2
by: Bill44077 | last post by:
Hi, I have a couple websites that use the ValidatorEnable(CompareValidator1, false) to disable the validator from firing on testing some conditions in js. My latest site is using...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
3
by: Rolf Welskes | last post by:
Hello, for a large web site project we would like to use nested Master Pages. Unfortunely VS2005 is not able to show pages in design mode when nested Master pages are used. This has the...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
3
by: Rich | last post by:
Hi, I want to use 2 master pages, one for the main part of the site, the other for the admin pages. They are quite similar, with many shared elements. Ideally I would like to have a parent...
2
by: yashgt | last post by:
Hi, We are looking for a tool that can be used by a non-developer admin user to visually move page elements around on a designer to automatically generate master pages. Is there such a tool...
18
by: Linny | last post by:
Hi, Came across this article in the ComputerWorld website which has included C in the top ten dying languages. The top 10 dead (or dying) computer skills...
2
by: Stratum | last post by:
It's an old question, and I apologize for raising it again. I use ImageButton objects on my ASP.Net master page to navigate to content pages. For each button, I have two images. One image shows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.