[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

RequiredFieldValidator Codebehind Not Showing on ASPX?

I think my code is correct, but I think I'm experiencing a "container-n-container" issue. I click the button, but nothing shows on the aspx page. Not sure how to use the FindControl to locate the PlaceHolder. Help...

[.aspx]
<table style="width: 100%; border: 0px solid #000000;" cellpadding="10px">
<tr>
<td>
<asp:Panel ID="Panel3" runat="server">
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View2" runat="server">
<div style="text-align: left; float: left; padding: 20px;">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server" Visible="False" Width="144px"
ontextchanged="txtName_TextChanged"></asp:TextBox>  
<br/>
<asp:PlaceHolder ID="phNameReqFieldVal" runat="server"></asp:PlaceHolder>
....

[.cs]
protected void Button1_Click(object sender, EventArgs e)
    {
        RequiredFieldValidator rfdTxtName = new RequiredFieldValidator();
        rfdTxtName.Display = ValidatorDisplay.Static;
        rfdTxtName.ControlToValidate = "txtName";
        rfdTxtName.ErrorMessage = "Required Field!";
               
        phNameReqFieldVal.Controls.Add(rfdTxtName);
}
0
pointeman
Asked:
pointeman
  • 4
  • 4
1 Solution
 
prairiedogCommented:
1. RequiredFieldValidator should fire by itself.
2. Why do you add your requiredfieldValidator in a PlaceHoder?
0
 
pointemanAuthor Commented:
2. I want the error message to appear in a specific page area...
0
 
prairiedogCommented:
Then use ValidationSummary control, instead of the PlaceHolder. You can put the ValidationSummary anywhere you like on your page.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pointemanAuthor Commented:
I like the Validation Summary contol, but still not showing. I think its a panel issue again. I'm using masterpages and the contact.aspx has one panel containing all controls, including other panels...
0
 
prairiedogCommented:
So this ValidationSummary control is on the Contact.aspx page? Can you post your code here?
0
 
pointemanAuthor Commented:
No, sorry for any confusion. I mean the textboxes are contained on the aspx page which has a main panel containing other panels, etc...
0
 
prairiedogCommented:
Some code will be helpful.
0
 
pointemanAuthor Commented:
ValidationSummary control makes life so much easier. Thanks...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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