Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate dynamic texbox's on button click
    primarykey
    data
    text
    <p>Alright so i've been dealing with this issue for two days now and i haven't solved the issue. I would like to validate the textbox's with RegularExpressionValidation.</p> <ol> <li>User selects yes or no from the dropbox</li> <li>if yes, then they click the button to open a form for inputs</li> <li>Fill out texbox's, not all are required but if they do fill in such as date then it has to be in the proper format.</li> <li>If valid the next button on the wizard is visible again and a new set of textbox's will show up. Note: the only time the next button shows up is if everything is valid.</li> </ol> <p><strong>My main issue is i want it to validate only this wizard step not the whole "page"</strong></p> <p>I keep getting the error whenever i click the button but it is probably from the regex. validate():</p> <p>System.NullReferenceException: Object reference not set to an instance of an object.</p> <pre><code>Source Error: Line 590: Line 591: Line 592: addressRegEx.Validate(); &lt;---Whats in red Line 593: EmployerRequired.Validate(); Line 594: phoneRegex.Validate(); </code></pre> <p>C#:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i &lt; TotalNumberAddedEmployment; ++i) { addcontrolsemployment(i + 1); } if (Wizard1.ActiveStep == WizardStep3) { Button nxtButton = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton"); nxtButton.Visible = false; } } public void addcontrolsemployment(int controlnumberEmp) { var newPanel = new Panel(); var employerLabel = new Label(); var addressLabel = new Label(); var phoneLabel = new Label(); var fromDateLabel = new Label(); var toDateLabel = new Label(); var supervisorLabel = new Label(); var jobTitleLabel = new Label(); var dutiesLabel = new Label(); var hoursLabel = new Label(); var wageLabel = new Label(); var leavingLabel = new Label(); var employerTextbox = new TextBox(); var addressTextbox = new TextBox(); var phoneTextbox = new TextBox(); var fromDateTextbox = new TextBox(); var toDateTextbox = new TextBox(); var supervisorTextbox = new TextBox(); var jobTitleTextbox = new TextBox(); var dutiesTextbox = new TextBox(); var hoursTextbox = new TextBox(); var wageTextbox = new TextBox(); var leavingTextbox = new TextBox(); // textbox needs a unique id to maintain state information employerTextbox.ID = "EmployerTextBox_" + controlnumberEmp; employerTextbox.Width = 250; //employerTextbox.Text = "Enter Employer Here"; addressTextbox.ID = "AddressTextbox_" + controlnumberEmp; addressTextbox.AutoPostBack = true; phoneTextbox.ID = "phoneTextbox_" + controlnumberEmp; phoneTextbox.AutoPostBack = true; fromDateTextbox.ID = "fromDateTextbox_" + controlnumberEmp; toDateTextbox.ID = "toDateTextbox_" + controlnumberEmp; toDateTextbox.AutoPostBack = true; supervisorTextbox.ID = "supervisorTextbox_" + controlnumberEmp; supervisorTextbox.AutoPostBack = true; jobTitleTextbox.ID = "jobTitleTexbox_" + controlnumberEmp; jobTitleTextbox.AutoPostBack = true; dutiesTextbox.ID = "dutiesTextbox_" + controlnumberEmp; dutiesTextbox.Width = 250; dutiesTextbox.AutoPostBack = true; hoursTextbox.ID = "hoursTexbox_" + controlnumberEmp; hoursTextbox.AutoPostBack = true; wageTextbox.ID = "wageTexbox_" + controlnumberEmp; wageTextbox.AutoPostBack = true; leavingTextbox.ID = "leavingTexbox_" + controlnumberEmp; leavingTextbox.Width = 250; leavingTextbox.AutoPostBack = true; //Label text employerLabel.Text = "Employer: "; addressLabel.Text = "Address: "; phoneLabel.Text = "Phone #: "; toDateLabel.Text = "To Date: "; fromDateLabel.Text = "From Date: "; supervisorLabel.Text = "Supervisor: "; jobTitleLabel.Text = "Job Title: "; dutiesLabel.Text = "Major Duties: "; hoursLabel.Text = "Hours Per Week:"; wageLabel.Text = "Final Wage: "; leavingLabel.Text = "Reason for Leaving: "; //Regular Expression and Required field validators var addressRegEx = new RegularExpressionValidator(); var EmployerRequired = new RequiredFieldValidator(); var phoneRegex = new RegularExpressionValidator(); var toDateRegex = new RegularExpressionValidator(); var fromDateRegex = new RegularExpressionValidator(); var supervisorRegex = new RegularExpressionValidator(); var jobTitleRegex = new RegularExpressionValidator(); var dutiesRegex = new RegularExpressionValidator(); var hoursRegex = new RegularExpressionValidator(); var wageRegex = new RegularExpressionValidator(); var leavingRegex = new RegularExpressionValidator(); EmployerRequired.Text = "Enter NA if No History"; EmployerRequired.ID = "employerRequired" + controlnumberEmp; EmployerRequired.ControlToValidate = employerTextbox.ID; EmployerRequired.ValidationGroup = "EmploymentValid"; addressRegEx.ValidationExpression = ".{0,50}"; addressRegEx.Text = "Please Enter less than 50 characters for address"; addressRegEx.ErrorMessage = "Please Enter less than 50 characters for address"; addressRegEx.ControlToValidate = addressTextbox.ID; //addressRegEx.ValidationGroup = "EmploymentValid"; phoneRegex.ID = "phoneRegex" + controlnumberEmp; phoneRegex.Text = "Please enter in (###)###-####"; phoneRegex.ControlToValidate = phoneTextbox.ID; phoneRegex.ValidationExpression = @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"; // phoneRegex.ValidationGroup = "EmploymentValid"; toDateRegex.ID = "toDateRegex" + controlnumberEmp; toDateRegex.Text = "Please enter in MM/DD/YYY form"; toDateRegex.ValidationExpression=@"^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$"; toDateRegex.ControlToValidate = toDateTextbox.ID; // toDateRegex.ValidationGroup = "EmploymentValid"; fromDateRegex.ID = "fromDateRegex" + controlnumberEmp; fromDateRegex.Text = "Please enter in MM/DD/YYY form"; fromDateRegex.ValidationExpression=@"^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$"; fromDateRegex.ControlToValidate = fromDateTextbox.ID; // fromDateRegex.ValidationGroup = "EmploymentValid"; supervisorRegex.ID = "supervisorRegex" + controlnumberEmp; supervisorRegex.Text = "Please enter in 20 characters or less"; supervisorRegex.ValidationExpression = ".{0,20}"; supervisorRegex.ControlToValidate = supervisorTextbox.ID; // supervisorRegex.ValidationGroup = "EmploymentValid"; jobTitleRegex.ID = "jobTitleRegex" + controlnumberEmp; jobTitleRegex.Text = "Please enter 30 characters or less"; jobTitleRegex.ValidationExpression = ".{0,30}"; jobTitleRegex.ControlToValidate = jobTitleTextbox.ID; // jobTitleRegex.ValidationGroup = "EmploymentValid"; dutiesRegex.ID = "dutiesRegex" + controlnumberEmp; dutiesRegex.Text = "Please enter 60 characters or less"; dutiesRegex.ValidationExpression = ".{0,60}"; dutiesRegex.ControlToValidate = dutiesTextbox.ID; // dutiesRegex.ValidationGroup = "EmploymentValid"; hoursRegex.ID = "hoursRegex" + controlnumberEmp; hoursRegex.Text = "Please enter up to 3 digits"; hoursRegex.ValidationExpression = "[0-9]{0,3}"; hoursRegex.ControlToValidate = hoursTextbox.ID; // hoursRegex.ValidationGroup = "EmploymentValid"; wageRegex.ID = "wageRegex" + controlnumberEmp; wageRegex.Text = "Please enter in currency format"; wageRegex.ValidationExpression = @"(?n:(^\$?(?!0,?\d)\d{1,3}(?=(?&lt;1&gt;,)|(?&lt;1&gt;))(\k&lt;1&gt;\d{3})*(\.\d\d)?)$)"; wageRegex.ControlToValidate = wageTextbox.ID; // wageRegex.ValidationGroup = "EmploymentValid"; leavingRegex.ID = "leavingRegex" + controlnumberEmp; leavingRegex.Text = "Please enter 60 characters or less"; leavingRegex.ValidationExpression = ".{0,60}"; leavingRegex.ControlToValidate = leavingTextbox.ID; // leavingRegex.ValidationGroup = "EmploymentValid"; // add the label and textbox to the panel, then add the panel to the form newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); //newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(new LiteralControl("&lt;table border='2px'&gt;&lt;tr&gt;")); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(new LiteralControl("&lt;td class='title-text' &gt;")); newPanel.Controls.Add(employerLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'width='180px' colspan='2'&gt;")); newPanel.Controls.Add(employerTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(EmployerRequired); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text' &gt;")); newPanel.Controls.Add(addressLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(addressTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(addressRegEx); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;")); newPanel.Controls.Add(new LiteralControl("&lt;td class='title-text'&gt;")); newPanel.Controls.Add(phoneLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(phoneTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(phoneRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(fromDateLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(fromDateTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(fromDateRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(toDateLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(toDateTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(toDateRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(supervisorLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(supervisorTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(supervisorRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(jobTitleLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(jobTitleTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(jobTitleRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(dutiesLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text' colspan='2'&gt;")); newPanel.Controls.Add(dutiesTextbox);//next to it newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(dutiesRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(hoursLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(hoursTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(hoursRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(wageLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(wageTextbox); newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(hoursRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='title-text'&gt;")); newPanel.Controls.Add(leavingLabel); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;td class='title-text' colspan='2'&gt;")); newPanel.Controls.Add(leavingTextbox); // next to it newPanel.Controls.Add(new LiteralControl("&lt;br /&gt;")); newPanel.Controls.Add(leavingRegex); newPanel.Controls.Add(new LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;hr&gt;")); addressRegEx.Validate(); EmployerRequired.Validate(); phoneRegex.Validate(); toDateRegex.Validate(); fromDateRegex.Validate(); supervisorRegex.Validate(); jobTitleRegex.Validate(); dutiesRegex.Validate(); hoursRegex.Validate(); wageRegex.Validate(); leavingRegex.Validate(); if((EmployerRequired.IsValid) &amp;&amp; (addressRegEx.IsValid) &amp;&amp; (phoneRegex.IsValid) &amp;&amp; (toDateRegex.IsValid) &amp;&amp; (toDateRegex.IsValid) &amp;&amp; (fromDateRegex.IsValid)&amp;&amp; (supervisorRegex.IsValid)&amp;&amp;(jobTitleRegex.IsValid)&amp;&amp;(dutiesRegex.IsValid)&amp;&amp;(hoursRegex.IsValid)&amp;&amp;(wageRegex.IsValid) &amp;&amp; (leavingRegex.IsValid)) { EmploymentPlaceHolder.Controls.Add(newPanel); } } protected int TotalNumberAddedEmployment { get { return (int)(ViewState["TotalNumberAddedEmployment"] ?? 0); } set { ViewState["TotalNumberAddedEmployment"] = value; } } protected void EmploymentButton_Click(object sender, EventArgs e) { Page.Validate(); if (Page.IsValid) { Button nxtButton = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton"); nxtButton.Visible = false; return; } else { // Increase the number added and add the new label and textbox TotalNumberAddedEmployment++; addcontrolsemployment(TotalNumberAddedEmployment); Button nxtButton = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton"); nxtButton.Visible = true; } } protected void ExperienceDropDownList_SelectedIndexChanged(object sender, EventArgs e) { if (ExperienceDropDownList.SelectedValue == "Yes") { Button nxtButton = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton"); nxtButton.Visible = false; addcontrolsemployment(1); } else { Button nxtButton = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton"); nxtButton.Visible = true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload