Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Validators inside Update Panel (VS2008)

I just noticed that if  I put validators inside update panels in Visual Studio 2008, they no longer function.  I must be missing something and I am sure this is an easy issue to deal with.  Can anyone give me any pointers here?

Thanks!
0
jglazer63
Asked:
jglazer63
  • 6
  • 6
  • 6
1 Solution
 
silemoneCommented:
this is a known error...and has always been the case


here a link that helps:

http://www.aspnettricks.com/archives/validators-inside-update-panel-doesnt-work-properly/
0
 
silemoneCommented:
just noticed you have vs2008..if you get vs2008 sp1, it's supposed to fix this...

http://stackoverflow.com/questions/124249/do-standard-asp-net-validators-work-with-ajax-and-update-panel
0
 
ajitha75Commented:
I tried this sample.. and it is working fine... Is there anything you have done? are both the controls and validators inside the updatepanel?

-Ajitha

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox2" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>

Open in new window

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
jglazer63Author Commented:
Well I updated to SP1 and i made no difference.  I am using a custom validator with a break point in the middle of it and its simply not firing.  I'll try putting the DLL in the BIN folder.
0
 
ajitha75Commented:
It depends on how the page is setup. Can you post your code here?
0
 
silemoneCommented:
if not...if its working before you place into update panel

do you have:

set the EnableClientScript property of the validators to false
0
 
jglazer63Author Commented:
Code is as follows.  Visibility of the chosen control is set to True at runtime.
   <asp:TextBox ID="txtCustomName" runat="server" Visible="False"></asp:TextBox>
                                    <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                        ControlToValidate="txtCustomName" CssClass="fielderror" 
                                        ErrorMessage="Missing or Invalid Page Name" Display="Dynamic" 
                                        EnableClientScript="False"></asp:CustomValidator>
                                    <asp:CustomValidator
                                            ID="CustomValidator2" runat="server" 
                                        ErrorMessage="Page Already Exists" ControlToValidate="txtCustomName" 
                                        CssClass="fielderror" Display="Dynamic" EnableClientScript="False"></asp:CustomValidator>

Open in new window

0
 
ajitha75Commented:
How are you mapping the Validate event (OnServerValidate) with the handler? I dont see that in the html definition.
0
 
silemoneCommented:
he's using: ControlToValidate ajitha


could you leave visibility as True and try it?  see if it works when the textbox is visible from the onset...
0
 
jglazer63Author Commented:
I did try visiility to true with no difference.
0
 
ajitha75Commented:
ControlToValidate is fine. But since you are using a CustomValidator, to validate in server side, I suppose you have an handler, which should be fired during postback. Do you have that? how is that attached to the Control event?
0
 
jglazer63Author Commented:
Yea, its set in the events.
0
 
ajitha75Commented:
ok. can you share your .cs code then?
0
 
jglazer63Author Commented:
I did confirm that bysimply removing the updatepanel, it works perfecly fine.  If its inside, no go.  Does that help?  not sure what the .CS code is.
0
 
ajitha75Commented:
.cs is code behind code... like for ex. where are you setting the textbox visibility to true?

-Ajitha
0
 
silemoneCommented:
I think the problem is the visiblity at preinit...its not seen...therefore not attached to the validator...that's why it may be better to have everything visible at the beginning and set up through the control...make any other changes such as visibility in page load...
0
 
jglazer63Author Commented:
That worked.  Thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 6
  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now