I have created visual webpart which as .net validation control. When i deploy part and try to insert into page i get error
This page contains content or formatting that is not valid. You can find more information in the affected sections. + webpart
Then i found code which i put in my webpart
private const string _ascxPath = @"~/MyProject/Webparts/Mywebpart.ascx";
protected override void CreateChildControls()
{
WebPartManager wp = WebPartManager.GetCurrentWebPartManager(this.Page);
if (wp.DisplayMode == WebPartManager.BrowseDisplayMode)
{
base.CreateChildControls();
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
}
But when i debug this code it is not going inside if condition if (wp.DisplayMode == WebPartManager.BrowseDisplayMode)
What could be reason?
Also if i forcefully take debugger inside if condition then i get error path is not valid which i have put in variable _ascxPath
What path should i put there?
**Update1**
Now i am trying to disable validation control as below but i get error
object reference not set to instance of object
Here is code
protected override void CreateChildControls()
{
bool pageIsEditMode = SPContext.Current.FormContext.FormMode == SPControlMode.Edit ? true : false;
if (pageIsEditMode)
{
RequiredName.Enabled = false;
}
else
{
RequiredName.Enabled = true;
}
}
Getting error on line RequiredName.Enabled = false;
RequiredName is asp validation control