Changing LabelText via Java Script
-
I have a label in my aspx page & iam changing its text via document.getElementById("LabelID"). innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.
Proud To Be an Indian
-
I have a label in my aspx page & iam changing its text via document.getElementById("LabelID"). innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.
Proud To Be an Indian
I have not tried this. Just a wild guess. Try changing to
innerText
.document.getElementById("LabelID").innerText = "SOmeText";
Navaneeth How to use google | Ask smart questions
modified on Monday, September 28, 2009 10:15 AM
-
I have not tried this. Just a wild guess. Try changing to
innerText
.document.getElementById("LabelID").innerText = "SOmeText";
Navaneeth How to use google | Ask smart questions
modified on Monday, September 28, 2009 10:15 AM
-
I have a label in my aspx page & iam changing its text via document.getElementById("LabelID"). innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.
Proud To Be an Indian
AFAIK, there is no way to get the value on server which is changed by JS for a label. Label is rendered as HTML span and the values of HTML elements like this are not posted to server. If you know CSS, you can make a text box look like a label and change the text box value. Please ignore my previous reply.
Navaneeth How to use google | Ask smart questions
-
Navaneeth, I think the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.
majee wrote:
the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.
For server controls, the
id
will be put as name. So what you are saying won't occur. The real issue here is a label render as HTML span and contents of span will not be posted to server. See my latest reply. :)Navaneeth How to use google | Ask smart questions
-
majee wrote:
the controls which don’t have the ‘name’ attribute wouldn’t maintain its contents on post back.
For server controls, the
id
will be put as name. So what you are saying won't occur. The real issue here is a label render as HTML span and contents of span will not be posted to server. See my latest reply. :)Navaneeth How to use google | Ask smart questions
-
I have a label in my aspx page & iam changing its text via document.getElementById("LabelID"). innerHTML = "SOmeText"; from JAVASCRIPT. Now by default an ASP.NET label should retain its contents. But its not. IS there any way to make it so I can change a label on the client-side and the contents persists back to the server? If iam using a textbox it does works fine.
Proud To Be an Indian
Use <asp:hiddenControl to change its value. Anything other than input types are reflects its changes through javacript in server (Not even Serverside ReadOnly/Disabled TextBoxes). So even if you change the innerHTML of the control, you will not find it in server side. Rather use
document.getElementById("hiddeninput").value = "SOmeText"; // To find the value in server
document.getElementById("LabelID").innerHTML = "SomeText"; // For display purpose only.I hope this will help you. :rose::rose:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Use <asp:hiddenControl to change its value. Anything other than input types are reflects its changes through javacript in server (Not even Serverside ReadOnly/Disabled TextBoxes). So even if you change the innerHTML of the control, you will not find it in server side. Rather use
document.getElementById("hiddeninput").value = "SOmeText"; // To find the value in server
document.getElementById("LabelID").innerHTML = "SomeText"; // For display purpose only.I hope this will help you. :rose::rose:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Thanks Friends .. thanks a lot for you support I implemented a textbox but since that textbox need not be Editable Can i change its style to that of a LABEL
Proud To Be an Indian
Of course budd. Just add a
Textbox
. In the server side add:txtbox.Attributes.Add("readonly", "readonly");
This will make the textbox readonly and also reflect any data being changed in the client. If you make
txtbox.Readonly = true / txtbox.Enabled = false;
the textbox value changed in the client will not reflect in the server. Hope you understand. :rose:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.