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
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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