user3467273
user3467273

Reputation:

Get value from textbox on .aspx page of server side

I am developing a Web Application in C#. In which the Default.aspx page runs on startup, on that page a JavaScript is loaded(run) which creates a simple textbox and button.

Both textbox and button are created by the JavaScript.

When I click on button it gets the value from textbox. Now I want the value on Default.aspx.cs side.

Problem:

How can I get this textbox value to the sever side (Default.aspx.cs)

Upvotes: 0

Views: 1496

Answers (3)

RKS
RKS

Reputation: 1410

1) If your textbox does not have runat="server" attribute, you can use the following method.

Create a hidden field which has runat="server" i.e. its a server-side control. Assign the value of this textbox to this hidden field on your button click(in javascript).

You can then access the value of the hidden field on the server-side.

2) If your textbox has runat="server" attribute, you can use the following method.

Request.Form["Name of Textbox"].ToString()

Upvotes: 1

santosh singh
santosh singh

Reputation: 28672

You can retrieve value from Request.Form collection.

 string strValue = Request.Form["Name of Control"].ToString();

Upvotes: 0

Raja Nadar
Raja Nadar

Reputation: 9499

some options:

  1. create a runat="server" based hidden field and assign textbox value to this.
  2. append the value in the querystring and access it server side using Request.QueryString

Upvotes: 2

Related Questions