0

Can I access server control values in aspx design page. For now being its just my curiosity but may be in need on tomorrow or so. For example I have a label in aspx page and I want to assign a textbox value to it.

I know I can use aspx.cs file instead but any desired suggestion will be highly appreciable.

Thanks in advance...... :)

1
  • Use Java Script for client side calculations Commented Apr 27, 2012 at 8:23

1 Answer 1

3

There are many ways.

1) var txtbox = Document.getElementbyId("<%= texboxId.ClientID%>"); txtbox.value = "new";

2) var txtbox = $("#" + "<%= texboxId.ClientID%>"); txtbox.value = "new";

3) var txtbox = $get("texboxId"); txtbox.value = "new";

If you are using Asp.Net 4.0 then the easy way is

<asp:TextBox runat="server" ID="txtboxId" ClientIDMode="Static" />

and access it directly without using ClientID.

1) var txtbox = Document.getElementbyId("txtboxId"); txtbox.value = "new";

2) var txtbox = $("#txtboxId"); txtbox.value = "new";

For number 2 you need Jquery and for number 3 you need Microsoft AJAX library.

Sign up to request clarification or add additional context in comments.

13 Comments

Thanks @Kamran Pervaiz don't know about software development but you have signs of a good teacher........ take care :)
<asp:TextBox ID="TextBox1" Text="Ajendra" runat="server"> </asp:TextBox> <asp:Label ID="Label2" runat="server" Text="<%#this.TextBox1.Text;%>"></asp:Label> Am I doing right ? getting error ")" missing. javascript is doing fine :)
what do you want to achieve? your code will just make the label text as textbox text. which you can do it in codebehind. Label2.Text = TextBox1.Text;
I want to assign the text of TextBox1 to Label2's text property using the same technique in a right way. I mean like I can concatenate the entered text to the text property of a link button to move to te new page with that entered parameter.
I know using code behind its very easy but I think how it will be done if I want to do it in design pade
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.