Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 控件内部的Asp.net按钮gridview不工作_C#_Asp.net_Gridview_Updatepanel_User Controls - Fatal编程技术网

C# 控件内部的Asp.net按钮gridview不工作

C# 控件内部的Asp.net按钮gridview不工作,c#,asp.net,gridview,updatepanel,user-controls,C#,Asp.net,Gridview,Updatepanel,User Controls,我需要显示一个客户机列表,但根据一个参数以不同的方式显示它们 为此,我有一个gridvew,里面有一个用户控件。该控件具有基于类型的“if” 我的问题: 如果我在控件中添加一个按钮,当它被按下时,我会得到一个按钮验证错误 如果禁用验证错误(enableEventValidation=“false”),则按钮命令可以工作,但无法使用完整回发或updatepanel更改控件上的值 <asp:GridView ID="gvClients" runat="server" AutoGenerateC

我需要显示一个客户机列表,但根据一个参数以不同的方式显示它们

为此,我有一个gridvew,里面有一个用户控件。该控件具有基于类型的“if”

我的问题:

  • 如果我在控件中添加一个按钮,当它被按下时,我会得到一个按钮验证错误

  • 如果禁用验证错误(enableEventValidation=“false”),则按钮命令可以工作,但无法使用完整回发或updatepanel更改控件上的值

    <asp:GridView ID="gvClients" runat="server" AutoGenerateColumns="False" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <xxx:ClientListGridItem ID="ClientListItem1" runat="server" Client='<%# ((Client) Container.DataItem) %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    </asp:GridView>
    
    
    
  • ClientListGridItem.ascx:

    <% if (Client.Style >= 100)
    {
       %>
     <div class="ClientListItem1">
    ...
    <% 
     }
    else
    {
        %>
     <div class="ClientListItem2">
     <asp:Button ID="Button2" runat="server" onclick="Button1_Click" Text="Button"  />
    ...
    <% 
     }
        %>
    
    =100)
    {
    %>
    ...
    ...
    

    我相信还有更漂亮、更面向对象的方法可以做到这一点……

    将ClientListGridItem.ascx更改为:

    <asp:Panel id="Div1" CssClass="ClientListItem1" runat="server">
    ...
    </asp:Panel>
    <asp:Panel id="Div2" CssClass="ClientListItem2"  runat="server">
     <asp:Button ID="Button2" runat="server" onclick="Button1_Click" CausesValidation="false" Text="Button"  />
    ..
    </asp:Panel>
    <script runat="server">
       override void OnDataBinding(EventArgs e) {
         Div1.Visible = Client.Style >= 100;
         Div2.Visible = ! Div1.Visible;
       }
    </script>
    
    
    ...
    ..
    重写无效OnDataBinding(事件参数e){
    Div1.Visible=Client.Style>=100;
    Div2.Visible=!Div1.Visible;
    }
    
    应该有用