public static class TextboxValidator
{
/// Test string using Regex.IsMatch static method.
public static bool Verify(string value)
{
return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$");
}
}
If that doesn't work, try this:
Right click on the .cs file in the App_Code folder and check its properties. Make sure the Build Action is set to Compile (http://stackoverflow.com/a/1222293/440310)
public static class TextboxValidator
cannot create new instances.
---------------
About the change properties to a .cs file is posible only when is a console application project, when is inside a App_Code
i heard it compiles automatically and change the properties to "compile" is not necesary.
I think the problem is how i call the static methods.
Thanks.
Creating an instance of TextboxValidator is a waste of time, you are trying to use a static method. The name of the static method is
TextboxValidator.Verify
When you type TextboxValidator and then press the . do you see the Verify method in an intellisense list?
If not, how did you create the App_Code folder? It is not a normal folder, you need to right-click the solution and choose 'Add ASP.NET Folder' => 'App_Code'. Does the icon for App_Code look like a normal folder or does it have a document in front of it?
If you do see Verify in the intellisense list then choose it. Your code would be something like
if (TextboxValidator.Verify(TextBox1.Text)) {your code}
(Note: don't put '=true', your code will not compile).
Are you sure the method is called 'Verify'? In the code that you claim works the method is called 'Veryfy'
When you say 'detects the program', exactly what do you mean? Does it mean that when you type TextboxValidator and then a . that you see Verify in the intellisense list?
Do NOT create an instance. Just to be sure, do NOT create an instance. Top tip - do NOT create an instance. (I may have mentioned this in my first post) Delete the line that says
TextboxValidator myValidator = new TextboxValidator();
On the next line, remove myValidator. and type
if (TextboxValidator.
You should see Verify in the intellisense list, choose it and then you can complete the statement
if (Textbox.Validator.Verify(Textbox1.Text)) { Whatever code you want }
novatgirl
Member
2 Points
18 Posts
unable to Call a class from App_Code Folder
Jan 07, 2013 11:48 PM|LINK
Please tell me how to call a class from APP_CODE folder
The small program returns true or false if a string match a Regex expresión where a trings contains letters and numbers.
I tested this program with Main method and it works in the same program using it as console application.
using System;
using System.Text.RegularExpressions;
public class TextboxValidator
{
/// Test string using Regex.IsMatch static method.
static bool Verify(string value)
{
return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$");
}
}
//static void Main ........
//Console.WriteLine(Veryfy("Coconut"));
//Console.WriteLine(Veryfy("MaliciousEntry$$%&&$$t"));
//output =true
//output = false
---------------------------------------------------------------
Now i want use the class in a Website and the class is stored in the App_Code folder.
When i create a new instance i don't see any problem, but no seems to load the static bool method.
TextboxValidator myValidator = new TextboxValidator
Verify(TextBox1.Text);
//or
if ( Verify(TexBox1.Text) = true ) {my code... }
thanks for your help.
oned_gk
All-Star
31227 Points
6379 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 12:01 AM|LINK
try
novatgirl
Member
2 Points
18 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 12:09 AM|LINK
Still i can create an instance :
TextboxValidator myValidator = new TextboxValidator();
but still no works,
no seems to load: "static bool Verify (string value) "
:(
Musikero11
Member
333 Points
182 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 12:34 AM|LINK
How about you try this one?
public static class TextboxValidator { /// Test string using Regex.IsMatch static method. public static bool Verify(string value) { return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$"); } }If that doesn't work, try this:
Right click on the .cs file in the App_Code folder and check its properties. Make sure the Build Action is set to Compile (http://stackoverflow.com/a/1222293/440310)
Musikero by night Musician's blog.
Don't forget to mark as "Answer" if that helps.
novatgirl
Member
2 Points
18 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 01:06 AM|LINK
after change to:
Paul Linton
Star
13403 Points
2531 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 01:38 AM|LINK
Do you have a Web Application or a Web Site?
Creating an instance of TextboxValidator is a waste of time, you are trying to use a static method. The name of the static method is
TextboxValidator.Verify
When you type TextboxValidator and then press the . do you see the Verify method in an intellisense list?
If not, how did you create the App_Code folder? It is not a normal folder, you need to right-click the solution and choose 'Add ASP.NET Folder' => 'App_Code'. Does the icon for App_Code look like a normal folder or does it have a document in front of it?
If you do see Verify in the intellisense list then choose it. Your code would be something like
if (TextboxValidator.Verify(TextBox1.Text)) {your code}
(Note: don't put '=true', your code will not compile).
Are you sure the method is called 'Verify'? In the code that you claim works the method is called 'Veryfy'
novatgirl
Member
2 Points
18 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 02:00 AM|LINK
I took the original code from here which i tested in a console application,
http://www.dotnetperls.com/regex-ismatch
Now i try to use it in a Website project, i have a folder called App_Code and intelisense detects the program, but i cannot use its static methods.
the icon of App_Code is the default icon when you create a Web project in VS20120.
For use the class in a web project, the "static void main" was removed, because i try to call the class from other files.
thanks
Paul Linton
Star
13403 Points
2531 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 02:02 AM|LINK
When you say 'detects the program', exactly what do you mean? Does it mean that when you type TextboxValidator and then a . that you see Verify in the intellisense list?
novatgirl
Member
2 Points
18 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 02:13 AM|LINK
using System;
using System.Text.RegularExpressions;
public class TextboxValidator
{
/// Test string using Regex.IsMatch static method.
static bool Verify(string value)
{
return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$");
}
}
---------------------------------
when i start typing Textbox, intelisense detects TexboxValidator from the App_Code folder
then i can create the instance:
TextboxValidator myValidator = new TextboxValidator();
myValidator. ///////// i dont see the verify method, intelisense does not detect it.
Paul Linton
Star
13403 Points
2531 Posts
Re: unable to Call a class from App_Code Folder
Jan 08, 2013 02:17 AM|LINK
Do NOT create an instance. Just to be sure, do NOT create an instance. Top tip - do NOT create an instance. (I may have mentioned this in my first post) Delete the line that says
TextboxValidator myValidator = new TextboxValidator();
On the next line, remove myValidator. and type
if (TextboxValidator.
You should see Verify in the intellisense list, choose it and then you can complete the statement
if (Textbox.Validator.Verify(Textbox1.Text)) { Whatever code you want }