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
445 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
ID: 38716167
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
ID: 38716329
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
ID: 38716590
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
ID: 38717584
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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