为什么HtmlSelect的ServerChange事件不能触发???
代码如下:
<select id="ProjectName" name="ProjectName" runat="server"></select>
private void InitializeComponent()
{
this.ProjectName.ServerChange += new System.EventHandler(this.ProjectName_ServerChange);
this.Add.ServerClick += new System.Web.UI.ImageClickEventHandler(this.Add_ServerClick);
this.Show.ServerClick += new System.Web.UI.ImageClickEventHandler(this.Show_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
private void ProjectName_ServerChange(object sender, System.EventArgs e)
{
}
它的ServerChange事件就是不触发,请问是什么原因
问题点数:50、回复次数:5Top
1 楼drk928(一起看斜阳)回复于 2004-09-01 16:59:27 得分 25
当然不会啦..它没有AUTOPOSTBACK
不过你可以用变态的方法来做.
this.ProjectName.Attribute("OnChange","document.all.Button1.click();")
在 Button1_Click 里实现.Top
2 楼breakshow(luohua)回复于 2004-09-01 17:06:46 得分 0
我加了AutoPostBask="True"还是不行啊,
HtmlSelect 没有Autopostback属性吗?Top
3 楼limeigui0725(你猜猜)回复于 2004-09-01 17:18:41 得分 25
在该控件的属性中重新添加一下这个事件:ProjectName_ServerChange,千万不要把代码复制一遍Top
4 楼breakshow(luohua)回复于 2004-09-01 17:25:01 得分 0
添加这个事件的代码有问题吗?Top
5 楼breakshow(luohua)回复于 2004-09-02 10:31:15 得分 0
我查看了csdn的例子,我没有发现我的代码有什么问题啊,
顺便说一下问题我已经用drk928(一起看斜阳)的方法解决了,现在只是想知道问题的原因.望那个高人站出来开导一下.
csdn上例子的代码:
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void Button_Click (Object sender, EventArgs e)
{
// Display the selected items.
Label1.Text = "You selected:";
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Label1.Text += "<br> -" + Select1.Items[i].Text;
}
}
void Server_Change(Object sender, EventArgs e)
{
// The ServerChange event is commonly used for data validation.
// This method will display a warning if the "All" option is
// selected in combination with another item in the list.
int Count = 0;
// Determine the number of selected items in the list.
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Count++;
}
// Display an error message if more than one item is selected with
// the "All" item selected.
if ((Count > 1) && (Select1.Items[0].Selected))
{
Label2.Text = "Hey! You can't select 'All' with another selection!!";
}
else
{
Label2.Text = "";
}
}
void Page_Load(Object sender, EventArgs e)
{
// Create an EventHandler delegate for the method you want to
// handle the event, and then add it to the list of methods
// called when the event is raised.
Select1.ServerChange += new System.EventHandler(this.Server_Change);
Button1.ServerClick += new System.EventHandler(this.Button_Click);
}
</script>
</head>
<body>
<form runat="server">
<h3> HtmlSelect Server Change Example </h3>
Select items from the list: <br><br>
<select id="Select1"
Multiple="True"
runat="server">
<option value="All"> All </option>
<option value="1" Selected="True"> Item 1 </option>
<option value="2"> Item 2 </option>
<option value="3"> Item 3 </option>
<option value="4"> Item 4 </option>
<option value="5"> Item 5 </option>
<option value="6"> Item 6 </option>
</select>
<br><br>
<button id="Button1"
runat="server">
Submit
</button>
<br><br>
<asp:Label id="Label1"
runat="server"/>
<br>
<asp:Label id="Label2"
runat="server"/>
</form>
</body>
</html>Top




