Solved

How do I check to see the value (if its empty or not) in TextBox1 from my class file (ASP.Net, C#)

Posted on 2012-12-22
4
441 Views
Last Modified: 2012-12-23
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

0
Comment
Question by:bmanmike39
4 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
Comment Utility
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
0
 

Author Comment

by:bmanmike39
Comment Utility
I don't know how to access the text box from my class file
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
Comment Utility
Hi,

Please check link: http://www.vss-tech.com/access-page-control-from-class-file-in-app_code/

to see how to access text box from .aspx page in class file(.cs) from App_Code.

Let us know if you face any problem.
0
 
LVL 19

Expert Comment

by:Manoj Patil
Comment Utility
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 />
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now