Why do the following result in a true if clause even though the textbox is empty and not even touched on a postback? :
<form action="Default.aspx" runat="server" method="post" id="newform">
<input type="text" id="name" runat="server"/>
</form>
<%
if (Request.Form["name"] != null) // Prints out "Name OK" on postback.
{
Response.Write("<br/>");
Response.Write("Name OK");
}
%>
Does the textbox actually contain an empty string ("") on a postback?
Why do the following result in a true if clause on the first page load but not on a postback? :
<form action="Default.aspx" runat="server" method="post" id="newform">
<input type="text" id="name" runat="server"/>
</form>
<%
if (Request.Form["name"] != "") // Prints out "Name OK" on first page load, but not on postback.
{
Response.Write("<br/>");
Response.Write("Name OK");
}
%>
To get a successful and expected result I have to use the following:
<form action="Default.aspx" runat="server" method="post" id="newform">
<input type="text" id="name" runat="server"/>
</form>
<%
if (Request.Form["name"] != null && Request.Form["name"] != "")
{
Response.Write("<br/>");
Response.Write("Name OK");
}
%>