Hello,
I want to create a custom WebDatePicker with an embedded RequiredFieldValidator... Here is my code:
System.Web.UI.WebControls.RequiredFieldValidator rfv;
protected override void CreateChildControls()
{
base.CreateChildControls();
rfv = new System.Web.UI.WebControls.RequiredFieldValidator();
rfv.ControlToValidate = this.ID;
rfv.ID = "rfv_" + this.ID;
rfv.ErrorMessage = "Error message";
rfv.Text = "*";
this.Controls.Add(rfv);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
base.Render(writer);
rfv.RenderControl(writer);
But I have this error:
I have tried this solution:
http://forums.infragistics.com/forums/p/50289/264449.aspx
protected override void OnInit(EventArgs e)
base.OnInit(e);
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
void Page_LoadComplete(object sender, EventArgs e)
//cv.ControlToValidate = this.UniqueID;
rfv.ErrorMessage = "Message erreur";
rfv.ControlToValidate = this.UniqueID;
this.Page.Form.Controls.Add(rfv);
It's work but my field validator is at the bottom of my page...
How can I put it next my control ?
Thanks,
Antonio
I have tried to do this:
int idx = this.Parent.Controls.IndexOf(this);rfvDate.EnableClientScript = true;this.Parent.Controls.AddAt(idx + 1, rfvDate);
But i have some issue when I disable the viewSate of the container...
So I can't disable the viewSate...
What can i try ?
Hi Antonio,
Please do not hesitate to contact me if you need further assistance regarding this matter.
In this scenario the validator may need to be placed inside a container whose viewstate is disabled. For more information regarding dynamically adding controls at a specific position please refer to :
http://msdn.microsoft.com/en-us/library/hbdfdyh7.aspx
Please feel free to contact me if you have any questions.
I have tried but I have an error:
Thank you for posting in the community.
Using the second approach you have described, I suggest that you add the validator to the form controls using the AddAt method to add the validator at a specified index. For instance:
this.Page.Form.Controls.AddAt(4, rfv);
Please let me know if this helps.