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
446 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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