Latest

random

Get Html Input Controls Value Server Side in ASP.Net

Obtain a value of an input (type text) on server side

Sometimes we need to create html controls dynamically on page and whenever some events raised like button or image button click event on server side code and we need to retrieve the values of those html controls as it is not declared as runat="server" on the page.

Here is the simple way to get values of the html input controls which doesn't have runat="server" attribute defined. Find the source code below:-
get html control values server side in asp.net, c#, without using runat="server",html control,  server side
C# - How to get value in html control on PostBack in ASP.Net
Default.aspx
<input type="text" name="_name"  />       
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />

Default.aspx.cs
protected void btnShow_Click(object sender, EventArgs e)
        {
            string strValue = Page.Request.Form["_name"].ToString();
            Response.Write(strValue);
        }[post_ad]

Note: To get the values on server side code of HTML control, we need to follow below points:
  • The tag should have an attribute called NAME. Because it is used as key in form[].
  • The form method should be of type POST.
I hope you will enjoy the development tips while programming with ASP.NET. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome. 

Also If you like this article, don't forget to share this article with your friends and colleagues.

10 comments:

  1. Its giving me Object reference not set to an instance of an object. Error, Why???

    ReplyDelete
    Replies
    1. It works fine with html input controls only. If you getting "Object reference not set to an instance of an object" error, to resolve this problem check your connection data source ..!!

      Delete
  2. I get the value its working fine thanks. But How to get the control type ? also ?

    ReplyDelete
  3. Hi Ravi,

    It' works fine....

    Thanks lot brother ............

    ReplyDelete

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.