aspx中下拉框的选中事件不能执行,单选框改变事件不能执行.解决办法
aspx中下拉框的选中事件不能执行,单选框改变事件不能执行.
下拉框的选中事件不能执行,单选框改变事件不能执行.
a.aspx<body>中的代码:
<form runat="server">
<input type="radio" id="man" name="gender" onChange="SelectMan" value="男" runat="server" >男
<input type="radio" id="woman" name="gender" onChange="SelectWoman" value="女" runat="server">女
<div runat="server" align="center">
省份:
<select id="area" runat="server" align="center" onChange="OnClickModifyArea">
<option>北京市</option>
<option>天津市</option>
<option>重庆市</option>
<option>上海市</option>
</select>
城市:
<input id="city" runat="server">
<input name="button" type="button" id="AddCity" value="增 加" onserverclick="OnClickAddCity" runat="server" />
</div>
</form>
</body>
a.aspx.cs:
//这个函数可以执行
public void OnClickAddCity(Object sender, EventArgs e)
{
Response.Write("add city");
}
//以下三个函数没有被调用
public void OnClickModifyArea(Object sender, EventArgs e)
{
Response.Write("1");
}
public void SelectMan(Object sender, EventArgs e)
{
Response.Write("man");
}
public void SelectWoman(Object sender, EventArgs e)
{
Response.Write("woman");
}
------解决思路----------------------
你的用服务器端控件吧。
单选框: <asp:RadioButton>.... </asp:RadioButton>
例子:
<form id="form1" runat="server">
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id="Radio1" Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br />
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><br />
<asp:RadioButton id="Radio2" Text="Compact" GroupName="RadioGroup1" runat="server"/><br />
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><br />
<asp:RadioButton id="Radio3" runat="server" Text="Full" GroupName="RadioGroup1" /><br />
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><br />
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server"/>
<asp:Label id="Label1" font-bold="true" runat="server" />
</form>
下拉框:<asp:DropDownList>...</asp:DropDownList>
例子:
<asp:DropDownList id="ColorList"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Silver"> Silver </asp:ListItem>
<asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>
</asp:DropDownList>
下拉框的选中事件不能执行,单选框改变事件不能执行.
a.aspx<body>中的代码:
<form runat="server">
<input type="radio" id="man" name="gender" onChange="SelectMan" value="男" runat="server" >男
<input type="radio" id="woman" name="gender" onChange="SelectWoman" value="女" runat="server">女
<div runat="server" align="center">
省份:
<select id="area" runat="server" align="center" onChange="OnClickModifyArea">
<option>北京市</option>
<option>天津市</option>
<option>重庆市</option>
<option>上海市</option>
</select>
城市:
<input id="city" runat="server">
<input name="button" type="button" id="AddCity" value="增 加" onserverclick="OnClickAddCity" runat="server" />
</div>
</form>
</body>
a.aspx.cs:
//这个函数可以执行
public void OnClickAddCity(Object sender, EventArgs e)
{
Response.Write("add city");
}
//以下三个函数没有被调用
public void OnClickModifyArea(Object sender, EventArgs e)
{
Response.Write("1");
}
public void SelectMan(Object sender, EventArgs e)
{
Response.Write("man");
}
public void SelectWoman(Object sender, EventArgs e)
{
Response.Write("woman");
}
------解决思路----------------------
你的用服务器端控件吧。
单选框: <asp:RadioButton>.... </asp:RadioButton>
例子:
<form id="form1" runat="server">
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id="Radio1" Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br />
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><br />
<asp:RadioButton id="Radio2" Text="Compact" GroupName="RadioGroup1" runat="server"/><br />
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><br />
<asp:RadioButton id="Radio3" runat="server" Text="Full" GroupName="RadioGroup1" /><br />
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><br />
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server"/>
<asp:Label id="Label1" font-bold="true" runat="server" />
</form>
下拉框:<asp:DropDownList>...</asp:DropDownList>
例子:
<asp:DropDownList id="ColorList"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Silver"> Silver </asp:ListItem>
<asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>
</asp:DropDownList>