Get value from JavaScript set label

I have a JavaScript which sets the innerHTML attrubute of a asp:Label like this: 

"document.getElementById(\"" + lbl.ClientID + "\").innerHTML = 'something....';");

But on postback I can't retrieve the value by calling lbl.Text as it's to save the javascript set value between postbacks?

9/5/2008 3:32:49 PM 93655 articles. 5 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 14

It should option is using "Session variable". Populate session variable in JS and read between postbacks.

 "Hidden Field" also a good opion.., Populate hiddenfield in JS and read from code-behind.. 

<input id="Hidden1" type="hidden" runat="server" />

Check this link, if you want to call server side function from java script

My Blog

"Don't be afraid to be wrong; otherwise you'll never be right."
9/5/2008 4:42:01 PM
What is "PageMethods" in the link example?
9/5/2008 5:29:40 PM
9/5/2008 8:28:52 PM

Pagemethods is undefined it says....a void function can't return a string and a hyperlink doesn't have a onclientclick property...could please give a better example? How to change the value of a label during runtime using javascript??

9/9/2008 7:53:44 AM
I have a JavaScript which sets the innerHTML attrubute of a asp:Label like this:

"document.getElementById(\"" + lbl.ClientID + "\").innerHTML = 'something....';");

But on postback I can't retrieve the value by calling lbl.Text as it's to save the javascript set value between postbacks?

Hi mm8,

Please refer the following code to solve your problem,

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void btnSubmit_Click(object sender, EventArgs e)

    protected void Page_Load(object sender, EventArgs e)
        lblMessage.Text = hdText.Value;

<html xmlns="">
<head id="Head1" runat="server">
    <title>Label Demo</title>

    <script language="javascript" type="text/javascript">
    function setValue()
        document.getElementById("lblMessage").innerHTML ="I Love ASP.NET !";  
        document.getElementById("hdText").value = document.getElementById("lblMessage").innerHTML;  

    <form id="form1" runat="server">
        <asp:Label ID="lblMessage" runat="server" Text="Demo"></asp:Label>
        <asp:Button ID="btnSubmit"
            runat="server" Text="Submit" OnClientClick="setValue();" 
            onclick="btnSubmit_Click" />
        <asp:HiddenField ID="hdText" runat="server" />
Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
9/10/2008 9:39:33 AM

It looks to me that you are mixing code behind added javascript rather than run time javascript. The time that the script runs will decide the final value. I coud be wrong on this next one, but I believe that setting the value of an asp label would be document.getElementById('lblClientId').value = "something...."


Hope that helps. If not then post some more of your code

9/10/2008 10:05:05 AM

Similar Artilces:

how to set get label control value in javascript.
How Can I get the label control let say Label1 text value in my javascript code.Kamran ShahidSr. Software Engineer(MCP,,,MCTS,[web])Netprosys Inc.www.netprosys.comRemember to click "Mark as Answer" on the post that helps U Hi, you can use document.getElementById(id of the label).innerText;1 <%@ Page Language="C#" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 4 5 <script runat="server"> 6 7 ...

Get label value on server side set by javascript
 HelloHow are all here.I have set the label text using javascriptdocument.getElementById("lblEmail").innerHTML = Login;Now when I try to get value (i.e. Text), by lblEmail.Text on ASP.Net server page, then the label shows no value or text. i.e. it is empty. why this is happening? how can I get value on Form set by Javascript?regards change in coding document.getElementById("lblEmail").value= "Hello World";   Please remember to click "Mark as Answer" on the post that helps you. This can be beneficial to other community members reading th...

Get values set by javascript to .net enabled textbox
I have a bit of javasript that writes a value to a text box.  The text box is read only. Textbox code:<input type="text" id="txtColor1" runat="server" readonly="readonly" size="6" /> Snippet from javascript functioncolorBox = document.getElementById('<%= txtColor1.ClientID %>');colorBox.value = colorCode;  Code behind:string color1 = txtColor1.Value Whenever I attempt to get the value out of the text box after it has been changed by the javascript, it always reverts back to the old data and not the new. Anyo...

How to set get label control value in javascript. #2
document.getElementByID("Label1") .innertext by this i can get label text by i want to get label value.can anyone help? Hi What do you actually mean by label value? asp:Label doesnt support any property called value . For eg if you declare a textBox something like this :- <asp:TextBox runat="server" ID="TextBox4" Text="Hii5"></asp:TextBox> then in borowser it is rendered as <input name="TextBox4" type="text" value="Hii5" id="TextBox4" /> so here you can see that you have value at...

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

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

Javascript Getting Label Value
Hi, I need help! I have a modal dialog popup that contains radio buttons for selecting save options. Buttons on the page call the modal with button related labels. I need to be able to disable some radio input buttons on the modal based upon the status of certain variables.  These values are within labels on the page. I tried to read label values from the javascript that loads the modal but the values are undefined. How can I capture label values within javascript? Values are populated on the page during a partial postback which I believe is causing the "undefined&qu...

how to set label value in javascript
I am having one web control label on webform. On chnage of textbox i am settting label.value = "change in textbox"  after on chnage event fire i am able to see label text is "change in textbox"  But on click of button when i see label.value Its empty. can anybody tell how i set my label value in javascript Hi, Its so very easy.... please see the following code and put it into your aspx file. <script lanugage=javascript runat=server> function ontextchange() {  document.getElementById("lableid").value = "change in text or whateve...

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

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.

To get the value form label in gridview
in aspx page  <asp:GridView ID="Gridview1" runat="server" Width="586px" OnRowCreated="Gridview1_RowCreated" > <Columns>     <asp:TemplateField HeaderText="SI.No"><ItemTemplate> Consultant <%# ((GridViewRow)Container).RowIndex%>     </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle CssClass="xGrid" /> <headerstyle backcolor="#869BB3" BorderColor="#CED6DD" />  </asp:GridView>   the displayed...

How to get TextBox value that was set by JavaScript
Hi, I used a JavaScript to set a TextBox value.  This works ok, it displays the correct value when the page is rendered.  But when I try to access the TextBox value using the server side code, it does not read the new value.  (I'm assuming it is because the JavaScript code is not actually adding the Text property to the rendered HTML) Here is my test code, does anyone have any ideas? protected override void OnLoad(EventArgs e) { base.OnLoad(e); TextBox tb = new TextBox(); tb.ID = "TestTextBox"; tb.Visible = true; tb.Text = "...

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

how to get value of a label in javascript function
Hey, In my code,I have a label in an ItemTemplate in a dropdownlist like this: <ItemTemplate> <asp:Label ID="qty_requested" Text='<%#DataBinder.Eval(Container.DataItem,"quantity") %>' runat ="server"></asp:Label> </ItemTemplate> and in the source code i got this : <span id="MyGrid_ctl02_qty_requested">1</span> My question is how can I access the Text value which is 1 in this case in my javascript function meaning that how to write the following replacing the ?????: varQuantity=eval("frmview.MyGrid_ctl02_qty_requested.?????"); Thank u in...

Web resources about - Get value from JavaScript set label -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 12/1/2015 10:38:12 PM