Click here to Skip to main content
Rate this: bad
good
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 2: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 at 8-Apr-11 8:18am
   
when ever i entered this it is showing cant place reg.exp.validator into a form
taher ahmed choudhury at 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 at 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 at 8-Apr-11 8:28am
   
Edit your post and show how you are doing this.
taher ahmed choudhury at 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 at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Dec 2013
Copyright © CodeProject, 1999-2014
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