I want to send form data to aspx.cs page view below codes.
But this error generated:Object reference not set to an instance of an object.
Please guide me.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post" action="Default2.aspx">
<input id="Text1" type="text" value="dgfdh" runat="server" name="Text1"/>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Request.Form["Text1"].ToString();
}
When you are running the page for the first time, there is no form yet (the aspx side is created after the cs part is run), and therefore
Request.Formhas no fields yet.Since the values of the form will be sent only upon submit (for example when clicking on a “Submit” button), you should put your assignment in a condition that checks if we’ve gotten to the page upon submit: