bmanmike39
asked on
How do I check to see the value (if its empty or not) in TextBox1 from my class file (ASP.Net, C#)
I would like to make a static class that check to see if a checkbox has something in it or not. And if it does, I want to execute my code. I just don’t know how to check the textbox
public class costCL
{
public double rs;
public void Add(double c, double s, double st)
{
if(don't know what goes here)
double ftax = 5.00;
rs = Math.Round(c + s + st + ftax, 2);
}
ASKER
I don't know how to access the text box from my class file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hey, if you want to restrict the user to enter the value in textbox then you can use regular expression n your .aspx page
Try it your self here
http://www.w3schools.com/aspnet/showasp.asp?filename=demo_reqfieldvalidator
Or you can check it by using java-script
function msgBox(objtxt)
{
var objtxt=document.getElement ById('<%=T extBox2.Cl ientId%>') ;
if (objtxt.value.length == 0)
{
alert('TextBox shouldnot be empty');
objtxt.focus();
}
}
<asp:TextBox ID="TextBox2" onkeyup ="msgBox(this);" runat="server"></asp:TextB ox><br />
Try it your self here
http://www.w3schools.com/aspnet/showasp.asp?filename=demo_reqfieldvalidator
Or you can check it by using java-script
function msgBox(objtxt)
{
var objtxt=document.getElement
if (objtxt.value.length == 0)
{
alert('TextBox shouldnot be empty');
objtxt.focus();
}
}
<asp:TextBox ID="TextBox2" onkeyup ="msgBox(this);" runat="server"></asp:TextB
If Not String.IsNullOrEmpty(TextB
execute your code
http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx