Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Get HTML Input Controls Values Server Side

Posted by Viral Sarvaiya on July 17, 2009

Many times a need arises to use HTML Controls rather than HTML controls. In that case the issue is how to get the values Server Side. See the example below

<input type = “text” id = “txt” value = “Hello” name = “txt” />

Now the name attribute is important Since Server Side You will need to access the controls using the name field. It is not necessary that the ID is same as the name it can be different

On Server Side

If Not Request.Params(“txt”) Is Nothing Then

Dim strVal As String = Request.Params(“txt”)

End If

Now most interesting part, suppose you have multiple TextBoxes and you need to get values of all of them then just give all of them same name attribute different ID is not an issue

<input type = “text” id = “txt1″ value = “Hello” name = “txt” />

<input type = “text” id = “txt2″ value = “Hello” name = “txt” />

<input type = “text” id = “txt3″ value = “Hello” name = “txt” />

<input type = “text” id = “txt4″ value = “Hello” name = “txt” />

<input type = “text” id = “txt5″ value = “Hello” name = “txt” />

Then on server Side

If Not Request.Params(“txt”) Is Nothing

Then Dim arr() As String = Request.Params(“txt”).Split(“,”)

For i As Integer = 0 To  arr.Length – 1

Dim strVal As String= arr(i)

Next End If

You will get values of all TextBoxes separated by comma.

Now you can split them and get it into an array as shown above

and the other way is also there, you can also use the “Request.form(“txt”) for geting the value of the html control.

This technique works for
1. TextBoxes
2. CheckBoxes
3. RadioButton
4.Select (DropDownList)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: