c#写的asp.net里面,if判断表单值是否为空,“”和null什么区别?
<scriptrunat="server"language="c#">voidPage_Load(){if(Request.Form["list1"]!=""){mess...
<script runat="server" language="c#">
void Page_Load()
{
if(Request.Form["list1"] !="")
{
message.Text="You have selected"+Request.Form["list1"];
}
}
</script>
<html>
<head>
<title>Drop Down List Example</title>
</head>
<body>
<asp:label id="message" runat="server" />
<br />
<form runat="server">
Which city do you wish to look at hotels for?<br /><br />
<asp:dropdownlist id="list1" runat="server">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:dropdownlist>
<br /><br /><br /><br />
<input type="Submit">
</form>
</body>
</html>
这个页面,当我用if(Request.Form["list1"] !="")的时候,运行结果错误,好像if没有起作用,我把""改为null后,运行结果就正确了,这是怎么回事,""不能用来判断是否为空的值吗? 展开
void Page_Load()
{
if(Request.Form["list1"] !="")
{
message.Text="You have selected"+Request.Form["list1"];
}
}
</script>
<html>
<head>
<title>Drop Down List Example</title>
</head>
<body>
<asp:label id="message" runat="server" />
<br />
<form runat="server">
Which city do you wish to look at hotels for?<br /><br />
<asp:dropdownlist id="list1" runat="server">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:dropdownlist>
<br /><br /><br /><br />
<input type="Submit">
</form>
</body>
</html>
这个页面,当我用if(Request.Form["list1"] !="")的时候,运行结果错误,好像if没有起作用,我把""改为null后,运行结果就正确了,这是怎么回事,""不能用来判断是否为空的值吗? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询