Get label value on server side set by javascript

 Hello

How are all here.

I have set the label text using javascript

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

1
azharrahi
3/18/2009 2:24:11 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies
13127 Views

Similar Articles

[PageSpeed] 35

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

1
Pratik
3/18/2009 2:37:55 PM

Hi,

The label control is a read-only control... you can't overwrite it from client side and maintain its value if a postback is executed.

To solve this issue... besides to write in the label, you can write the same value in a HiddenField control... and retrieve the value of the HiddenField from the server:

document.getElementById("lblEmail").innerHTML = Login;

document.getElementById("hiddenField1").value = Login;

Any doubt, post your comment.


Segundo Serrano P.
Ing. Sistemas
http://www.4workgroup.com/
Blog: http://dotnet-peru.blogspot.com
3
Segundo
3/18/2009 2:38:02 PM

Try this:

document.getElementById(<%# lblEmail.ClientID %>).innerHTML = Login;

1
bhavana_p
3/18/2009 2:38:38 PM
 As mentioned, you cannot specify value to the Label control using Javascript. Use a hidden variable... 

<input type="hidden" name="hidVal" id="hidVal" runat="server" />

 And use this in the javascript...

document.getElementById('<%=hidVal.ClientID %>').value = 'Login'; 

You can access the hidden variable directly from the server side code....

string strVal = hidVal.Value;

Hope it helps.


KAMMIE
Don't forget to Mark as Answer on the post that helped you. It encourages them to share their knowledge, and it helps others to easily identify the solution.
6
kammie
3/18/2009 4:01:26 PM

Great answer and code man!.. you saved my day and my project.

This works like a charm.

I really thank you  Yes

1
Peug206
3/26/2009 1:40:45 PM
Reply:

Similar Artilces:

Setting the value of server side variable in javascript and wants to use that server side variable on page load.
Hi, I am trying to set the value of a server side variable in javascript and wants to use that variable on page load.  Here is my sample code. -------------------------- private string testVal = null;  private void registerScript(){ if (!this.Page.ClientScript.IsClientScriptBlockRegistered("RequestHeaderValidation")){ StringBuilder sb = new StringBuilder("" + Environment.NewLine);sb.Append(" var version = '2.0'; " + Environment.NewLine); sb.Append(" var isInstalled = Silverlight.isInstalled(version);" + Environment.NewLine)...

Is there any possible way that forms authentication can work on a web farm w/o each servers machine key values being set to the same thing?i have a site that is on a web farm and the servers dont have
 Is there any possible way that forms authentication can work on a web farm w/o each servers machine key values being set to the same thing?i have a site that is on a web farm and the servers dont have the machine keys set......but the forms authentication works fine. "Only when we are no longer afraid do we begin to live" -D. Thompson // f bush. ----------- "No man succeeds without a good woman behind him. Wife or mother, if it is both, he is twice blessed indeed." -Harold MacMillan A couple of things spring to mind. 1. Some form of "st...

Get value from JavaScript set label
I have a JavaScript which sets the innerHTML attrubute of a asp:Label like this: ..... sb.Append("document.getElementById(\"" + lbl.ClientID + "\").innerHTML = 'something....';"); But on postback I can't retrieve the value by calling lbl.Text as it's blank...how to save the javascript set value between postbacks? It should work..one 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 co...

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite 7.1.0.300) Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

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,MCAD.net,MCSD.net,MCTS,MCPD.net[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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <script runat="server"> 6 7 ...

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

How to set value of a server control on Clint side using javascript.
I have defined toDayHidden filed in .aspx as     . <form>    ......    <asp:Label ID="toDayHidden" runat="server" Text="";></asp:Label>    ....</form> On the client side I would like to set the value of this label to a date value so that I can use the client date on the server. I tried the following but it does not set the value of this control but it does not set the value of the control. document.getElementById('<%= toDayHidden.ID %>').innerText = new Date(); and also document.getElementById('<%= toDayHidden.ID %>').value = new Date(); What can I do to set the value of the control?     Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer. Any help on this? Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer. SKVSKV:I have defined toDayHidden filed in .aspx as     . <form>    ......    <asp:Label ID="toDayHidden" runat="server" Text="";></asp:Label>    ....</form> On the client side I would like to set the value of this label to a date value so that I can use the client date on the server. I tried the following but it does not set the value of...

How to get control value changed by javascript unload event in server side?
I use javascript to change the value of a HtmlInputHidden control during window.onunload event. However, the ASP.NET server side code can only get the value before the change. How can this be solved?   Hi, the clientside event "onunload" occurs at all times when the user navigate to a new page. A postback is not effected every time after the onunload event. Try to use the onsubmit event and attach an event method at the end of the page, e.g.: </body> <script> window.document.form1.attachEvent("onsubmit", SetValue); </script> </html>RegardsMarc A...

How can a value assigned to a label using Javascript can be accesed from the server side?
Hi All,I am creating an Order form for our project, in this I am doing some calculations and assigning value to a label using Javascript. document.getElementById(lblAmountPayable).innerHTML = amountpayable.toFixed(2);   The value is displayed properly . After this I am trying to access these values in a button click to save these values, but it's returning me empty string  How can I do that ??RegardsSudheep   hi, the value assigned to label through javascript will be lost during post back you need to use a hidden filed to store the value and in server si...

Hidden Field that is set on server side...not getting the last updated value from client?
Hi, I have a hidden field that tracks errors in my server side asp.net 2.0 code.  However, when I set the value to an error (from it's default value "NotSet") in the server side code and then when trying to access that Hidden Variable from the client the value is still set to the default value, "NotSet" instead of the error information. Any ideas as to what is going on here? Thanks in advance!   Server Side....  catch (Exception er) { Errors.Value = er.Message; o o o } Client Side.... function getErrors() { var cho = document.getElementById('<%=Errors.ClientID...

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

How to get the Client side values in server side code.
Hi all, i have a proble i need to get the client side javascript values in C# code at server side. how can i pass those values? i am using version 1.1, i kno thatwe can use callback events mechnisam in 2.0 or ajax ,apart from that how we can pass? My problem is i need to stop the execution of the code based on after reciving values from the client   any ideas please???   Million thanks RamCheersRam MCP Hello Ram, a common approach is from javascript set an hidden field, then issue a postback. On the server-side, handle the post-back. Feel free to go deeper in your que...

Getting hidden variable value from server side in client side
hi,        I am struck in problem. I have a hidden field in my form and i am setting some value in that.         Now i wnt to use this value from client side but i m not able to retrieve it. All i am getting there is an object.         I feel the hidden field is not able to hold that value.         <input type="hidden" id="hdnVar" runat="server" />         in code behind      ...

Updateting Server side variable through javascript or how can i user Javascript variable in server side C# ?
 Hi I am new for web development. I wasted fewdays but I am not able to figureout following problem.1. I have Javascript variable I want to use in Server side C# is it possible ?2. If above is not possible if i declare variable in C#  and is it possible to update through Javascript ?As I am new for web development Please give me sample code for example it will be very easy for me to understand. If  both way possible please explain me both way. Thanks in anticipationHarshad   Yes it is possible to get the value of your javascript variable in C#. here's how:1. In...

GridView with Labels updated by JavaScript (client side) and PageMethod (server side)
I have a gridview and I'm computing a column with javascript.Example.Column 3 = Column 1 + Column 2; Therefore all three columns are templated items. It's working like a charm.. HOWEVER - and this is not good at all - upon reading the values to pass them to a webservice it of course doesn't take the client side updates values.I'm using JavaScript because otherwise I wouldnt be able to use the onKeyUp event. And I want desperatly want the onKeyUp to offer realtime updates for the calculated values rather dann forcing the user to push a "recalculate button".So.. I bas...

Problem accessing server side array values from javascript client side function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>; First of all, you can't mix server-side and client-side code. The reason is that the protocol that is used to communicate betwee...

Problem accessing server side array values from client side javascript function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>;...

textbox value set on client side, is not visible on server side or, on the source of the page.
hi, I have a textbox on my webform. the first time I load my page I fill this textbox with  "name" on the server side. once the page is loaded I set the value of the textbox to "thisIsme" with client side code. I even see a different text in the texbox. client side:document.all('txtnameInput').value =  'thisIsme'; server side:Me.txtnaam.Text 'is stil "name" and not "thisIsme" Why is this happening? on the webpage I see the text "thisIsme", but when I look at the source of the webpage I still see the old value in it. it's very odd... I am NOT setting the value back to "name" on the page load event of the postback. any idea's why this is happening ?see my blog at www.Interdevelopments.com and check the future of open mobile widget solutions at www.glowe.org When you look at the "source code" of a web page, you see the HTML which was originally sent from the server, if you change any value inside any element on client side (textboxes, selects, checkboxes...) you won't see it on the "source code", but the "page" object into the browser does keep them well. Now if you don't get the rigth value ("thisIsme") when you submit the form back to the server that could be a different issue....

how do i get selectedValue of drop down list server side if i am populating it using client side javascript?
 Hi All.I am populating a drop down list client side using: The drop down list is populated based on a selection of another drop down list. ddlList.options[i] = new Option(1,2); as an exampleThe populating is done as i need it to. However, a button click event i am trying to get the selectedValue of the ddlList. However, it doesn't give me it. It only gives me the selectedValue of the drop down list on first rendering. Any ideas on how i can get it?   Could You paste some code? That would be helpful. Thanks S@ss (Shashi Shekhar Singh)My BlogPlease mark a post as ANSWER ...

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

server side controls in a non-server side form
I want to use server side controls in a non-server side form.I use server side controls (like dropdownlists) so I can fill them with the right options from the database.My question is, what is the best way to approach this?CAN I use server-side controls in a client side form? If so, how can I get the values contained in the controls when I do a post? (not in a querystring).Here's a sample of my code: <form id="frmAdvancedSearch" method="post" action="advancedSearch.aspx"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <input type="submit" /> </form>...

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

Web resources about - Get label value on server side set by javascript - asp.net.web-forms

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 Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

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

Quickstart: Facebook SDK for JavaScript
This quickstart will show you how to setup the SDK, load social plugins, trigger a dialog, and get it to make some basic Graph API calls.

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

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 . blog.mozilla.org/research/2014/… ...

Resources last updated: 3/9/2016 6:26:18 AM