Get value in code behind

How to get value in code behind from source,

I assign text value to Label in source file and want to get text of same lable in code behind  file, but i am not able get value in code behind.

please give me reply if possible 

Pirana Dargah
2/26/2008 3:24:16 PM 93655 articles. 5 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 13

I assume you mean that in your .aspx or .ascx file you have something like this:

<asp:label id='lblTest' runat='server' text='Hello' />

And you want to get access to the value in your code file. Assuming this is true you can access the label's properties using its id. For example, above I specified that the label's id is 'lblTest" so in my code file I can access the label's text property (or any other property) like this:

lblTest.Text = "New Value";


If this post answered your question please remember to 'Mark as Answer'!
2/26/2008 3:41:07 PM

What is your code look like??  Should be like label1.text = ????  in code behind, that should give you the value of label1


Click on 'Mark as Answer' if this post is helpful.

-- Randy
2/26/2008 3:42:21 PM

AzharSaiyed :

How to get value in code behind from source,

I assign text value to Label in source file and want to get text of same lable in code behind  file, but i am not able get value in code behind.

please give me reply if possible


Hi AzharSaiyed ,

Are you using HTML controls or ASPNET controls? IF you are using ASPNET server controls then you can easily Access the Values by using the TEXT property of the Control.. For example if you wanted to get the value of a Label/TextBox then you can simply do something like this in your Code behind..

string value1 = TextBox1.Text;

string value2 = Label1.Text;

But if you are using HTML controls then be sure to add the runat="server" attribute and give an ID for that control for you to access that in your code behind.


"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
2/26/2008 4:44:28 PM

solve it
Pirana Dargah
5/21/2008 6:10:59 AM

Similar Artilces:

Web Forms Designer error
Hi, The web forms designer keeps adding things in a generated InitializeComponent() method. I believe these things shouldn't be there because I've made a new webform with the same code that doesn't add the same stuff. Is there anyway I can see the Web Designer code? Thanks. Just expand out the hidden #region. It is labeled Web Form Designer CodeStarting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog...

get html textbox value in behind)
  i am new to Can anybody say how to get Input textbox value in b4 sending answer Thankx  string value = Resquest.Form["textboxname"].ToString(); Hi,There are two ways to access it. 1) Make it runat="server" and access it in code behind like textbox1.value2) Another way is by using     Request.Form["textbox1"].ToString(); I hope this will be helpful to you.Thanks, Alpesh DhaneshaPlease don't forget to "Mask as Answer" if it helped. just add runat =server to html  ...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

Getting undefined value while using view state in Web Form Designer generated code
hi,    i am trying to get the drop down list selected value in Web Form Designer generated code,when i am trying it with view state i am getting some undefined value.please help me regarding this.. i am trying with the following code.        refinery =  ddRefineries.SelectedRefinery; ViewState.Add("ref1",refinery); #region Web Form Designer generated code        override protected void OnInit(EventArgs e)        {          &nbs...

how can i convert code behind web forms pages to inline code pages
hi all of you, I have a problem, a have registered a free space at Brinkster , so i can just upload my files there one by one, but can not install my web application directly, and i have to upload my projects there, so one way is o convert all my VS.NET web application which is code behind, convert that into inline code, so how can i do that Thanks in advanceWarm Regards,Prajesh Kumar JhaE-MAIL : Convert from Code-Behind to Code-Inline: Darrell Norton, MVPDarrell Norton's BlogPlease m...

validate web form entries via textbox again in the C# (code-behind) code again
I have requiredfieldvalidators, comparevalidators and a regualarexpressionvalidator for the email on my login form for the textboxes. My question is do I have to check in the C# to make sure the textboxes have values and if so what does a experienced programmer think of my code. What would you change??? Are the if statements the way to go??? Thanks for making me a better coder................newbieprotected void LoginButton_Click(object sender, EventArgs e){string emailAddress = String.Empty;string password = String.Empty;if (!String.IsNullOrEmpty(TextBoxEmailAddress.Text)){emailAddress = Te...

how to change these windows form code to web form code?
hi, i'm a beginner of c#,i want to know how to change these windows form code to web form code //////////// private void buttonSign_Click( object sender, System.EventArgs e) { //get original message as byte array byte[] messagebytes = Encoding.UTF8.GetBytes( textOriginalMessage.Text); //create digest of original message using SHA1 SHA1 sha1 = new SHA1CryptoServiceProvider(); byte[] hashbytes = sha1.ComputeHash(messagebytes); //display hash bytes in hex format StringBuilder sb = new StringBuilder(); for (...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

How to get the HREF value of the Anchor tag in a web page using the web browser control in
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

How to change list items in a DDL with values from VB code in code behind with web using master pages?
In the old days using plain asp I used to know how to do this (without the master page of course), but I haven't had need for several years. Since we are using master pages as well, is there a good tutorial or explanation that covers how to pass a list of values from a database query in VB.NET to JScript variables, when master pages are being used? Thanks for any help.     Why would master pages make a difference?  A master page just wraps the page you're working in, so you would still pull the data from the DB the same way.    Let me know if I've misund...

not getting boundfield value in code behind
Hi, I am having one gridview like this, <asp:GridView ID="GridView1" runat="server" ForeColor="Blue" Width="705px" style="left: 7px; position: absolute; top: 410px" AutoGenerateColumns="False" Font-Size="Smaller" Height="136px" OnRowDeleting="GridView1_RowDeleting"><RowStyle BackColor="BlanchedAlmond" BorderColor="SandyBrown" /><Columns><asp:TemplateField HeaderText="Action"><ItemTemplate><asp:HyperLink ID="actionlink" Text='...

How to get a value from code behind to source
I am trying to get a session value to the sqldatasource on the html page. I use the session value in the VB code behind but can't seem to get it to the source page. The underlined, bold text below is what I'm needing. Thanks for any help. <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DevConnectionString4 %>" SelectCommand="SELECT convert(varchar,[PersonID ]) + ' - ' + LastName1 + ', ' + FirstName1 AS PersonIDandName, PersonID FROM vwChecklistPeople WHERE Number = SESSION VALUE...

Get listbox value from the other web form
 Dear all, I want to get the lisbox selecteditem value to a textbox in one web form from the other web page. Should I use session to get this value?Can any one help in this regard? Thanks a lot in advance.  People Develop People Yes you can use Session to get the informations between cross pages.. see below for your referenceTO STORE THE INFO in Session Session["key"] = ListBox1.SelectedItem.Value; Response.Redirect("Page2.aspx");TO GET THE VALUES FROM Sessionprotected void Page_Load(object sender, EventArgs e){    if (Sessio...

Get string value from code behind
 I cant get string value from code behind. Please help me. this is my code. this is in aspx page<div class="username"> <%GetLanguage("BACK.INDEX.USERNAME");%> </div>  in this code. GetLanguage is a method which return a string value. GetLanguage is ok but return value can't show.Never give up, never quit Try this: <%= GetLanguage("BACK.INDEX.USERNAME") %>Thanks, EdMicrosoft MVP - ASP/ASP.NET Hello,try out what ecbruck said, also ensure the GetLanguage method is mark as public ~ Remember to mark as Answer, if i...