Get html control value in code behind without runat = server

access html control value in codebehind without runat server
In application we need to access value of html control in code behind without runat="server". For that purpose we can use name property of control. And Request.Form we can get value to code behind.So if we have html text input and you want to pass value of html input to code behind set it name property like <input name="username" />  and access it using Rquest.Form["usename"] you will get value to code behind of control without runat="server".

Code to get html control value to code behind without runat server

<html xmlns="">
<head runat="server">
  <script type="text/javascript">
      function SubmitForm() {
         var theform;
          if (window.navigator.appName.toUpperCase().indexOf("NETSCAPE") > -1) {
              theform = document.forms["form1"];
          else {
              theform = document.forms.form1;
          theform.__EVENTTARGET = "btn";   
          theform.__EVENTARGUMENT = "";
    <form id="form1" runat="server">
        <input type="text" id="username" name="username" />
        <input type="button" id="btn" onclick="SubmitForm()"  value="GO"/>

Code behind to access html control value

using System;

namespace aspnetcontrol
    public partial class Getvaluewithoutrunatservercontrol : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            string value = Request.Form["username"];


Post a Comment