Ajendra Prasad
Ajendra Prasad

Reputation: 327

How to access server controls for eg. Textbox values in aspx page?

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

Upvotes: 0

Views: 1547

Answers (1)

Kamran Pervaiz
Kamran Pervaiz

Reputation: 1931

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.

Upvotes: 3

Related Questions