Click here to Skip to main content
12,403,130 members (72,712 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Application Web
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 8-Apr-11 1:59am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Its not that difficult.
RegularExpressionValidator validator = new RegularExpressionValidator();
validator.ControlToValidate = textbox.ClientId;
validator.ValidationExpression = "[0-9]";
TableCell.Controls.Add(validator);
  Permalink  
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:
Mark Nischalke 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);
Mark Nischalke 8-Apr-11 11:04am
   
What part of edit your post did you not understand? DON'T keep adding replies, this is information that should have been included in your original post.

What is cnew? Where are you doing all of this? All you have done is basically repeat what I gave you.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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);
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 9 Dec 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100