setvalue of asp:Label with JavaScript

A

Anton ml. Vahèiè

Hi,

Can anyone tells me how can I set value of asp:Label field with JavaScript?

Anton, ml.
 
A

Anton ml. Vahèiè

Basically I want to get some values from client browser and use/write them
in my asp:label.

Anton, ml.
 
D

Dan

How about creating a cookie using javascript and then picking this up using
your code behind?
 
A

Anton ml. Vahèiè

Hi,

That's good idea, but I don't want to have cookies behind my code... I
read somewhere that it can be done with RegisterHiddenField. I create a
hiddenfield even change value, but then how I read hidden field back to my
variable in asp.net program... Examples about it are not too perfect in MS
documentation.

Anton, ml.
 
B

Beamer310

Hello Anton,

I believe you have to something like this:

var elMyElement = document.getElementByID("ElementName");

elMyElement.innerHTML = "your text here";

Adam
 
S

Shahar

Dan said:
How about creating a cookie using javascript and then picking this up using
your code behind?

<form id="frmMain" method="post" runat="server">
<asp:Label ID="lbl" Runat="server"></asp:Label>
</form>


private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterStartupScript("initLabel", "<script>document.all['" +
lbl.ClientID + "'].innerText='some value';</script>");
}
 
T

ThatsIT.net.au

A label with the id "myLabel" renders as a span if the page uses master
pages the id will be changed, it will have a prefix starting with ctl00. you
need to find that Id in the source and then use it in your JavaScript to
change the spans innerText or innerHTML

to get the client id of the server control you can also use
<%=myLabel.clientId%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,133
Latest member
MDACVReview
Top