Repeater 的ItemCommand事件不响应-----我遇到的诡异的问题(已解决)

原创 2007年09月27日 15:19:00
今天碰到一个页面,Repeater的Itemcommand事件死活不响应,网上搜了一搜,问的人还真多,可能解决的很少,估计是各有各的原因。像其他人所说的什么事件没有注册啊,ispostback没有判断啊等等,通通都不属于我存在的问题。我当时很是奇怪,因为我弄了个测试页面,上面只有一个repeater,没有其他任何东西,这个repeater就能响应的好好的。所以问题还是出现在那个页面上。经过反复试验,终于有了一个惊人的发现:
原来,页面上包含一个用户控件head011,内容大致如下
<script language="javascript" type="textjavascript">
var domainroot="www.sina.com.cn"// 你的网站域名 
  function Gsitesearch(curobj)
  curobj.q.value
="site:"+domainroot+" "+curobj.qfront.value 
  }
 
</script>
<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">注意此处很关键
    
<br>
    
<table width="765" border="0" align="center" cellpadding="0" cellspacing="0">
        
<tr>
            
<td width="250"><img src="images/l001.gif" width="250" height="61"></td>
            
<td width="510" valign="bottom"><table width="0" border="0" align="right" cellpadding="0" cellspacing="0">
                    
<tr>
                        
<td>
                            
&nbsp; <href="index.aspx" class="ch007">首页</a> <href="lxwm.aspx" class="ch007">
                                联系我们
</a> <href="yqlj.aspx" class="ch007"></a>
                        
</td>
                    
</tr>
                
</table>
            
</td>
        
</tr>
    
</table>
    
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
        
<tr>
            
<td><img src="images/l002.gif" width="768" height="29"></td>
        
</tr>
    
</table>
    
<table width="768" border="0" align="center" cellpadding="0" cellspacing="0">
        
<tr>
            
<td width="247" height="23" background="images/l003.gif">&nbsp;</td>
            
<td width="307" background="images/l003.gif"><href="gywm_gsjj.aspx"><img src="images/l019.gif" width="62" height="23" border="0"></a><href="xw_lb.aspx"><img src="images/l020.gif" width="75" height="23" border="0"></a><href="tzzgx_llwm.aspx"><img src="images/l021.gif" width="86" height="23" border="0"></a><href="ywjs.aspx"><img src="images/l022.gif" width="60" height="23" border="0"></a></td>
            
<td width="64" background="images/l003.gif"><select name="select" size="1" class="table001">
                    
<option selected>标题</option>
                    
<option>内容</option>
                    
<option>作者</option>
                
</select></td>
            
<p>
                
<td width="110" background="images/l003.gif"><input name="q" type="hidden"><input name="qfront" type="text" class="table002" value="搜索内容" size="20"></td>
                
<td width="40" background="images/l003.gif"><input type="submit" class="table003" value="go"></td>
            
</p>
        
</tr>
    
</table>
</form>

而出问题的页面大致如下:
<%@ Register TagPrefix="uc1" TagName="down02" Src="Controls/down02.ascx" %>
<%@ Register TagPrefix="uc1" TagName="left01" Src="Controls/left01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="head01" Src="Controls/head01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="meta01" Src="Controls/meta01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="title01" Src="Controls/title01.ascx" %>
<%@ Page CodeBehind="xzym.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="Exhibition.web.xzym" %>
<HTML>
    
<HEAD>
        
<uc1:meta01 id="meta011" runat="server"></uc1:meta01>
        
<uc1:title01 id="title011" runat="server"></uc1:title01>
        
<link href="ch.css" rel="stylesheet" type="text/css">
    
</HEAD>
    
<body topmargin="0">
    
<form id="Form1" runat="server" method="post">注意此处很关键
        
<uc1:head01 id="head011" runat="server"></uc1:head01>注意此处很关键
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="images/l002.png" width="767" height="138"></td>
            
</tr>
        
</table>
        
<table width="767" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td width="190" valign="top" bgcolor="#f3f3f3">
                    
<uc1:left01 id="left011" runat="server"></uc1:left01>
                
</td>
                
<td width="580" valign="top"><table width="100%" height="33" border="0" align="center" cellpadding="0" cellspacing="0">
                        
<tr>
                            
<td width="580" height="33" background="images/l034.gif">&nbsp;<img src="images/l017.gif" width="10" height="11"><href="index.aspx" class="ch003">首页&gt;</a><href="#" class="ch008">
                                    下载页面
</a></td>
                        
</tr>
                    
</table>
                    
<br>
                    
<table width="90%" height="26" border="0" align="center" cellpadding="0" cellspacing="0">
                        
<tr>
                            
<td width="84%" background="../images/ch_l_063.gif" class="ch001">&nbsp;<span class="ch003"><strong>资料下载 
                                        :
</strong></span></td>
                            
<td width="16%" background="../images/ch_l_063.gif" class="ch004">点击下载</td>
                        
</tr>
                    
</table>
                    
<asp:Repeater id="Repeater1" runat="server">
                        
<HeaderTemplate>
                            
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td align="center" valign="top" background="../images/ch_l_066.gif">
                        
</HeaderTemplate>
                        
<ItemTemplate>
                            
<table width="511" height="65" border="0" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td width="429" height="65" align="left" class="ch007"><%# DataBinder.Eval(Container, "DataItem.FileDownName")%>(<%# DataBinder.Eval(Container, "DataItem.FileSize")%>)</td>
                                    
<td width="82" align="center"><asp:ImageButton id="lbtn_download2" runat="server" ImageUrl ="../images/ch_l_067.gif" Width="35" Height ="28" BorderWidth ="0" CommandName ="download" CommandArgument ='<%# DataBinder.Eval(Container, "DataItem.FileID")%>'></asp:ImageButton><span class="ch005"><br />
                    Download
</span></td>
                                
</tr>
                            
</table>
                        
</ItemTemplate>
                        
<AlternatingItemTemplate>
                            
<table width="511" height="65" border="0" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td width="429" height="65" align="left" class="ch007"><%# DataBinder.Eval(Container, "DataItem.FileDownName")%>(<%# DataBinder.Eval(Container, "DataItem.FileSize")%>)</td>
                                    
<td width="82" align="center"><asp:ImageButton id="ibtn_download1" runat="server" ImageUrl ="../images/ch_l_068.gif" Width ="35" Height ="28" BorderWidth ="0" CommandName ="download" CommandArgument ='<%# DataBinder.Eval(Container, "DataItem.FileID")%>'></asp:ImageButton><span class="ch005"><br />
                    Download
</span></td>
                                
</tr>
                            
</table>
                        
</AlternatingItemTemplate>
                        
<FooterTemplate>
                
</td>
            
</tr>
        
</table>
        
</FooterTemplate> </asp:Repeater>
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="../images/dna01.gif" width="500" height="9"></td>
            
</tr>
        
</table>
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="../images/ch_l_056.gif" width="550" height="10"></td>
            
</tr>
        
</table>
        
</td> </tr> </table>
        
<uc1:down02 id="down021" runat="server"></uc1:down02>
        
</form>
    
</body>
</HTML>

这样的两个分别都要提交的FROM的结构,存在问题,导致了Itemcommand的事件不能响应。我虽然找到了原因,但并不知道原理是什么,还请高手赐教,不胜感激。
所以针对我的这个页面的问题来说,就很好解决了,把页面改成如下的结构,问题就迎刃而解了:
<%@ Register TagPrefix="uc1" TagName="down02" Src="Controls/down02.ascx" %>
<%@ Register TagPrefix="uc1" TagName="left01" Src="Controls/left01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="head01" Src="Controls/head01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="meta01" Src="Controls/meta01.ascx" %>
<%@ Register TagPrefix="uc1" TagName="title01" Src="Controls/title01.ascx" %>
<%@ Page CodeBehind="xzym.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="Exhibition.web.xzym" %>
<HTML>
    
<HEAD>
        
<uc1:meta01 id="meta011" runat="server"></uc1:meta01>
        
<uc1:title01 id="title011" runat="server"></uc1:title01>
        
<link href="ch.css" rel="stylesheet" type="text/css">
    
</HEAD>
    
<body topmargin="0">
         
<uc1:head01 id="head011" runat="server"></uc1:head01>注意此处很关键---------将这句话提到FORM的外面去
    
<form id="Form1" runat="server" method="post">    注意此处很关键    
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="images/l002.png" width="767" height="138"></td>
            
</tr>
        
</table>
        
<table width="767" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td width="190" valign="top" bgcolor="#f3f3f3">
                    
<uc1:left01 id="left011" runat="server"></uc1:left01>
                
</td>
                
<td width="580" valign="top"><table width="100%" height="33" border="0" align="center" cellpadding="0" cellspacing="0">
                        
<tr>
                            
<td width="580" height="33" background="images/l034.gif">&nbsp;<img src="images/l017.gif" width="10" height="11"><href="index.aspx" class="ch003">首页&gt;</a><href="#" class="ch008">
                                    下载页面
</a></td>
                        
</tr>
                    
</table>
                    
<br>
                    
<table width="90%" height="26" border="0" align="center" cellpadding="0" cellspacing="0">
                        
<tr>
                            
<td width="84%" background="../images/ch_l_063.gif" class="ch001">&nbsp;<span class="ch003"><strong>资料下载 
                                        :
</strong></span></td>
                            
<td width="16%" background="../images/ch_l_063.gif" class="ch004">点击下载</td>
                        
</tr>
                    
</table>
                    
<asp:Repeater id="Repeater1" runat="server">
                        
<HeaderTemplate>
                            
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td align="center" valign="top" background="../images/ch_l_066.gif">
                        
</HeaderTemplate>
                        
<ItemTemplate>
                            
<table width="511" height="65" border="0" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td width="429" height="65" align="left" class="ch007"><%# DataBinder.Eval(Container, "DataItem.FileDownName")%>(<%# DataBinder.Eval(Container, "DataItem.FileSize")%>)</td>
                                    
<td width="82" align="center"><asp:ImageButton id="lbtn_download2" runat="server" ImageUrl ="../images/ch_l_067.gif" Width="35" Height ="28" BorderWidth ="0" CommandName ="download" CommandArgument ='<%# DataBinder.Eval(Container, "DataItem.FileID")%>'></asp:ImageButton><span class="ch005"><br />
                    Download
</span></td>
                                
</tr>
                            
</table>
                        
</ItemTemplate>
                        
<AlternatingItemTemplate>
                            
<table width="511" height="65" border="0" cellpadding="0" cellspacing="0">
                                
<tr>
                                    
<td width="429" height="65" align="left" class="ch007"><%# DataBinder.Eval(Container, "DataItem.FileDownName")%>(<%# DataBinder.Eval(Container, "DataItem.FileSize")%>)</td>
                                    
<td width="82" align="center"><asp:ImageButton id="ibtn_download1" runat="server" ImageUrl ="../images/ch_l_068.gif" Width ="35" Height ="28" BorderWidth ="0" CommandName ="download" CommandArgument ='<%# DataBinder.Eval(Container, "DataItem.FileID")%>'></asp:ImageButton><span class="ch005"><br />
                    Download
</span></td>
                                
</tr>
                            
</table>
                        
</AlternatingItemTemplate>
                        
<FooterTemplate>
                
</td>
            
</tr>
        
</table>
        
</FooterTemplate> </asp:Repeater>
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="../images/dna01.gif" width="500" height="9"></td>
            
</tr>
        
</table>
        
<table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
            
<tr>
                
<td><img src="../images/ch_l_056.gif" width="550" height="10"></td>
            
</tr>
        
</table>
        
</td> </tr> </table>
        
<uc1:down02 id="down021" runat="server"></uc1:down02>
        
</form>
    
</body>
</HTML>

我的问题是解决了。可我最终还是不知道,为什么将那个包含一个form的<uc1>提到页面Form标签的外面去,就能解决这个问题。换句话说,为什么<uc1>放到页面的Form标签的里面,就能造成itemcommand事件的不响应呢??盼望高手的解答。。。。。。
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

GridView的RowCommand事件和DataList的ItemCommand事件

GridView           CssClass="GridViewStyle" PageSize="10" AllowPaging="true&q...

Repeater 的操作,数据的显示,绑定,动态取控件中的值和Repeater1_ItemCommand事件的相关用法

%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  .....

Repeater中OnItemCommand无法触发事件

有时候无法触发事件,有时候可以添加以下代码后都可以了: protected void Page_Load(object sender, EventArgs e) { ...

Aspose.Words使用word模板中的书签插入图片(导出含有图片的word)

核心代码为: protected void Button2_Click(object sender, EventArgs e) { string templatePath = ...

对android里布局文件当中的TextView对象设置事件监听,但是不响应问题解决

对android里布局文件当中的TextView对象设置事件监听,但是不响应问题解决

Repeater 控件的 ItemCommand 事件

下面的示例演示如何指定和编写 Repeater控件的 ItemCommand 事件的处理程序。 当单击 Repeater控件中的某个 Button控件时,会显示有关该按钮的信息。 <!DOCTYPE...

解决Cordova多页面注册backbutton事件,一个页面响应过事件以后,其他页面不响应的问题

cordova backbutton

Repeater 的操作,数据的显示,绑定,动态取控件中的值和Repeater1_ItemCommand事件的相关用法

HTML Code 昵称:这是[]帅哥于[]...

【Android问题集】ListView不响应onItemClick事件

作者:Yogi前言:在机顶盒的直播应用项目中遇到listview完全不响应onItemClick事件,但是响应onItemSelected事件,这个问题该怎么解决呢?解决思路listView不响应on...

android listview 长按事件setOnItemLongClickListener不响应问题

我的Listview同时设置了2个监听事件 setOnItemLongClickListener(长按事件) 和点击事件,但是点击事件我是在adapter的getView()里面设置的, 代码如下:...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)