DropDownList设置AutoPostBack="true"后自动回发失效问题
网页中现有一个DropDownList,已经AutoPostBack="true",在本机测试运行良好,但是传到服务器上自动回发就失效了,代码如下:<%@PageLang...
网页中现有一个DropDownList,已经AutoPostBack="true",在本机测试运行良好,但是传到服务器上自动回发就失效了,代码如下:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If choice.SelectedItem.Text = "选择题" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "判断" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "填空" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "简答" Then
Response.Write(choice.SelectedItem.Text)
End If
'Response.Write("dd")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<asp:DropDownList runat="server" ID="choice" AutoPostBack="true">
<asp:ListItem>选择题</asp:ListItem>
<asp:ListItem>判断</asp:ListItem>
<asp:ListItem>填空</asp:ListItem>
<asp:ListItem>简答</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
请问这个是什么引起的,该怎么解决? 谢谢 展开
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If choice.SelectedItem.Text = "选择题" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "判断" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "填空" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "简答" Then
Response.Write(choice.SelectedItem.Text)
End If
'Response.Write("dd")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<asp:DropDownList runat="server" ID="choice" AutoPostBack="true">
<asp:ListItem>选择题</asp:ListItem>
<asp:ListItem>判断</asp:ListItem>
<asp:ListItem>填空</asp:ListItem>
<asp:ListItem>简答</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
请问这个是什么引起的,该怎么解决? 谢谢 展开
2个回答
展开全部
DropDownList用法用错了;百度下例子
双击你的DropDownList
会自动生成对应的事件
protected void choice_SelectedIndexChanged(object sender, EventArgs e)
{
//这里写你的代码
If choice.SelectedItem.Text = "选择题" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "判断" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "填空" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "简答" Then
Response.Write(choice.SelectedItem.Text)
End If
}
还有就是如果用ajax的updatepanel 这个控件不包起来的话 页面就不会刷新,不然你DropDownlist选择不同选项会刷新整个页面
双击你的DropDownList
会自动生成对应的事件
protected void choice_SelectedIndexChanged(object sender, EventArgs e)
{
//这里写你的代码
If choice.SelectedItem.Text = "选择题" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "判断" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "填空" Then
Response.Write(choice.SelectedItem.Text)
ElseIf choice.SelectedItem.Text = "简答" Then
Response.Write(choice.SelectedItem.Text)
End If
}
还有就是如果用ajax的updatepanel 这个控件不包起来的话 页面就不会刷新,不然你DropDownlist选择不同选项会刷新整个页面
更多追问追答
追问
用法肯定没有错,在我自己的电脑上都能正常运行的
追答
应该每次提交的时候都刷新页面
所以你写在Page_Load事件里 也不算错 规范应该写在Change事件里的
发布服务器上没试过,在自己电脑上发布了下 没问题的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询