Link to home
Start Free TrialLog in
Avatar of bmanmike39
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);
    }
         

Open in new window

Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

You can use the IsNullOrEmpty method to check the value.

If Not String.IsNullOrEmpty(TextBox.Text) then
execute your code


http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx
Avatar of bmanmike39
bmanmike39

ASKER

I don't know how to access the text box from my class file
ASKER CERTIFIED SOLUTION
Avatar of Vikram Singh Saini
Vikram Singh Saini
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Manoj Patil
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.getElementById('<%=TextBox2.ClientId%>');
if (objtxt.value.length == 0)

{
alert('TextBox shouldnot be empty');

objtxt.focus();

}

}



<asp:TextBox ID="TextBox2" onkeyup ="msgBox(this);" runat="server"></asp:TextBox><br />