Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have crated a table dynamically and inside table i created dynamic text box.
i want to use validator for individual cell to validate for numeric only.
Posted

Its not that difficult.
RegularExpressionValidator validator = new RegularExpressionValidator();
validator.ControlToValidate = textbox.ClientId;
validator.ValidationExpression = "[0-9]";
TableCell.Controls.Add(validator);
 
Share this answer
 
Comments
taher ahmed choudhury 8-Apr-11 8:18am    
when ever i entered this it is showing cant place reg.exp.validator into a form
taher ahmed choudhury 11-Apr-11 1:12am    
i tried in cell showing the errors like that

Server Error in '/' Application.
The ControlToValidate property of '' cannot be blank.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The ControlToValidate property of '' cannot be blank.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The ControlToValidate property of '' cannot be blank.]
System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +8730985
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +21
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +27
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.W
taher ahmed choudhury 8-Apr-11 8:20am    
Control 'ctl12' of type 'RegularExpressionValidator' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'ctl12' of type 'RegularExpressionValidator' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[no name] 8-Apr-11 8:28am    
Edit your post and show how you are doing this.
taher ahmed choudhury 8-Apr-11 8:32am    
i m doing like that

itxt.Value = chrgdr["ofc"].ToString();
itxt.ID = "itxt";
RegularExpressionValidator validator = new RegularExpressionValidator();
validator.ControlToValidate = itxt.ID;
validator.ValidationExpression = "[0-9]";
cnew.Controls.Add(validator);


cnew.Controls.Add(itxt);
TableCell tdTextbox = new TableCell();
RegularExpressionValidator regularExpressionValidator =
new RegularExpressionValidator
{
ID = string.Concat("RegularTextBoxDynamicValidator", m_FilteredTextBoxExtender),
Display = ValidatorDisplay.Dynamic,
ForeColor = System.Drawing.Color.Red,
ErrorMessage = "Invalid Charecters",
ControlToValidate = textBox.ID,
SetFocusOnError = true,
ValidationExpression = @"^[A-Za-z\s0-9" + allowedSpecialCharacters + "]*$"
};
tdTextbox.Controls.Add(textBox);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900