CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

为什么HtmlSelect的ServerChange事件不能触发???

楼主breakshow(luohua)2004-09-01 16:56:02 在 .NET技术 / ASP.NET 提问

代码如下:  
  <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

相关问题

  • 事件触发
  • OnCalcFields事件触发
  • Button触发事件
  • 怎样触发OnFilterRecord事件
  • TimerSetEvent如何触发事件?
  • 咋样触发MultiPage1.SelectedIndexChange事件
  • ActiveX触发事件问题
  • 如何触发事件?
  • contextmenu事件不触发
  • 末能触发事件

关键词

得分解答快速导航

  • 帖主:breakshow
  • drk928
  • limeigui0725

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo