Disabling Validators for a page postback

I have an asp.net page (using C#) named title.aspx with a dropdownlist, validator, and linkbutton:

<script language="javascript">
// Creates a new pop-up window for users to enter new dropdownlist items in
function NewWindow(url)
{
var sHTML = "<html><frameset frameborder='no' rows='20%,80%'>" +
"<frame src='common/windowcloser.htm' name='frame1' scrolling='no' noresize>" +
"<frame src='" + url + "' name='frame2' scrolling='yes' noresize>" +
"</frameset></html>"
      
// Create a window object and write the html to it
var win = window.open("", "win", "width=700,height=400");
                        
win.document.open("text/html", "replace");
win.document.write(sHTML);
win.document.close();
}
</script>
<table>
<tr>
<td><asp:textbox id="txtDesc" runat="server" /></td>
</tr>
<tr>
<td style="WIDTH: 229px" align="right"><b>Title:</b></td>
<td align="left">
<asp:dropdownlist id="ddlTitle" runat="server" DataValueField="Title_Lit" DataTextField="Title_Lit" onclick="NewWindow('applicanttitlelist.aspx')"></asp:dropdownlist>
<asp:requiredfieldvalidator id="rfvTitle" ControlToValidate="ddlNewTitle" Display="Static"  Runat="server">*</asp:requiredfieldvalidator>
<br>
<asp:LinkButton ID="lnkAdd" Runat="server" CausesValidation="False" >Add</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:button id="btnSave" tabIndex="20" runat="server" Text="Save" CssClass="buttons" />
</td>
</tr>
</table>

lnkAdd opens a new window where a user can add a new record to the table that populates the ddlTitle dropdownlist.  There is a button in the new window that performs the following javascript when clicked:

top.opener.document.applicantadd.submit();
top.window.close();

I need the new window to refresh the ddlTitle dropdownlist when the new window is closed (which it does already with the submit() javascript function).  However, the problem is that when the submit() function is performed, the validators on the title.aspx page are fired.

Is there any way to cause these validators not to fire when the new window is closed?

FYI - These validators need to be working so they can be utilized by the btnSave button on the title.aspx page.
cwhite85Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cwhite85Author Commented:
Also, I use submit because I do not want any text that has been entered into the txtDesc textbox to be erased on the postback.
0
LosBearCommented:
how about permanently stopping them just for that page?

include this in your <% @page   header

validateRequest="false"

you might be able to call this in the ispostback function in your page_load routine, but I haven't tried it before.

good luck
bear
0
cwhite85Author Commented:
I cant permanently stop the validators from running.  I need them to check for correct values in my controls when the btnSave is clicked.

Is there any other way?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

LosBearCommented:
tricky,
you are probably using javascript to refresh the page when the other window closes?

(this is going to be messy)
-create a hidden field
-when the window closes, pass a value to the parent window
-have the form auto-resubmit at this point
-when it resumbits, if the hidden field contains data, then

If hdnField.Value = "something" Then
     validateRequest = "false"
End If

if this is what you want to happen, then I can post code if you want
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cwhite85Author Commented:
Yes that will work - can you please post some example code for it?
0
LosBearCommented:
Ok,

Add a hidden field on the parent form:


      <form name="frmMain" id="frmMain" runat="server">
            <input type="hidden" name="hdnField" id="hdnField" runat="server" />
      </form>


You can change the name of the form, but make sure you change it in the javascript below:
Next, paste this in the child window place this into the head


      <script language="javascript">
      <!--
            function CopyEmail(ThisValue) {
                  top.opener.window.frmMain.hdnField.value = 'DONOTVALIDATE';
                  self.close();
            }
      //-->
      </script>

This will fill the hidden field with the value "DONOTVALIDATE"
Next you want the parent to form to auto submit, so paste this into the body tag of the CHILD

      <body onload="parent.opener.location.reload();">

If you want to close the window AND resubmit the page, use this:

      <body onload="self.close();parent.opener.location.reload();">
      
Finally, in the parent's Page_Load routine, place this:

Sub Page_Load
      If IsPostBack Then
            If hdnField.Value = "DONOTVALIDATE" Then
                  validateRequest = "false"
            End If
      End If
End Sub
      
Ok, I think this is it :)
0
cwhite85Author Commented:
What object is validateRequest a method or property of?
0
LosBearCommented:
I researched it, and you can only use the validateRequest in either the web.config file or as part of the @Page property
When u said that the validator would fire, are you talking about the <asp:RequiredFieldValidator id="rfvTitle"......
control?  If you are just replace validateRequest="False" to    

rfvTitle.Enabled = False

0
cwhite85Author Commented:
What I ended up doing is using the javascript:

top.opener.document.forms[0].submit();
top.window.close();

when the 'Close Window' button is pressed in the new window.

This way the opener of the new window is postbacked and the new window is closed.  

When the new window is originally opened, the original page has an onlclick event that is called when the link that opens the new window is clicked.  In that onclick event, I set  a ViewState variable (ViewState["IsEditMode"]) equal to a false value.  Then on the postback when the new window is closed, there is an if statement on the load event that checks the ViewState variable.  If the variable is false, all the validators are disabled on the page, if it is true then the validators are all set to true.  This way the validators are only set to false when the new window is opened and true when the new window is not opened.

Thanks for the effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.