【问题标题】:Usercontrols which don't trigger events for visitors不为访问者触发事件的用户控件
【发布时间】:2008-12-11 18:57:01
【问题描述】:

此 UpdatePanel 包含在 UserControl 中。当 LinkBut​​ton 被按下时,箭头应该被添加到另一个 GridView 中。当用户登录时,此控件运行良好。 当用户未登录并尝试按下该按钮时,就会出现问题。没有事件触发器。 有人建议我在 web.config 中授予访问此控件的权限。那没有用。 有人有其他想法吗?

<asp:UpdatePanel runat="server" UpdateMode="Conditional" EnableViewState="true" ID="IngredientsUpdatePanel">
<ContentTemplate>
    <asp:ObjectDataSource ID="sourceIngredients" runat="server" SelectMethod="GetAll">
    </asp:ObjectDataSource>
    <asp:GridView ID="Ingredients" AllowPaging="true" runat="server" DataKeyNames="IngredientId"
        EnableViewState="true" DataSourceID="sourceIngredients" PageSize="5"
        AutoGenerateColumns="false" HorizontalAlign="Center" OnSelectedIndexChanged="Ingredients_SelectedIndexChanged">
         <RowStyle HorizontalAlign="Center"  />  
         <HeaderStyle Font-Bold="true" ForeColor="Black" /> 
         <Columns>                        
                <asp:TemplateField HeaderText="Ingrediente" ItemStyle-Font-Size="10">                
                    <ItemTemplate>
                        <asp:Label ID="lblId" Text='<%# Bind("IngredientId") %>' Visible="false" runat="server"/>
                        <asp:Label ID="lblPrice" Text='<%# Bind("Price") %>' Visible="false" runat="server"/>
                        <asp:Label ID="lblDescr" Text='<%# Bind("Description") %>' Visible="false" runat="server"/>
                        <asp:Label ID="lblName" Text='<%# Bind("Name") %>' Visible="false" runat="server"/>
                        <asp:Label ID="lblPict" Text='<%# Bind("Picture") %>' Visible="false" runat="server"/>
                        <div style="text-align:left;">                        
                            <img id="img" style="float:right;" src='<%# Eval("Picture") %>'
                                height="75" runat="server" alt="Picture" />                                                    
                            <b>
                                <%# Eval("Name") %>
                            </b>
                            <br />
                            <br />
                            Price: <b><%# Eval("Price") %></b>
                            <br />
                            <br />
                            <br />
                        </div>                    
                        <hr />
                        <div style="text-align:left;">
                        <b>Description</b>
                        </div>
                        <div style="width:300px;">
                            <%# Eval("Description") %> 
                        </div>
                        <br />
                        <asp:LinkButton Enabled="true" runat="server" Text="Add" CommandName="Select" ID="cmdAdd" />                           
                       </ItemTemplate>            
                </asp:TemplateField>
             </Columns>
    </asp:GridView>
</ContentTemplate>

【问题讨论】:

    标签: c# asp.net user-controls


    【解决方案1】:

    我以一种棘手的方式解决了这个问题。 我删除了 LinkBut​​ton,在 TemplateField 之前我放了一个 ButtonField,一切正常。 现在代码看起来像:

     <Columns>
      <asp:ButtonField Text="Add" CommandName="Select" />                 
          <asp:TemplateField>
                ......
          </asp:TemplateField>
     </Columns>
    

    我仍然不明白为什么控件有这种行为。

    【讨论】:

      【解决方案2】:

      别忘了在 web.config 中给 webresource.axd 足够的权限?

      【讨论】:

      • 嗯,我不使用那个文件...但是我添加了那行,它不起作用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多