Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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回发未命中正确的方法_C#_Asp.net_Postback - Fatal编程技术网

C# ASP.NET回发未命中正确的方法

C# ASP.NET回发未命中正确的方法,c#,asp.net,postback,C#,Asp.net,Postback,考虑以下ASP.NET代码: <asp:UpdatePanel runat="server" ChildrenAsTriggers="true"> <ContentTemplate> <asp:MultiView runat="server" ID="MultiView" ActiveViewIndex="0"> <asp:View runat="server

考虑以下ASP.NET代码:

<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
            <ContentTemplate>
                <asp:MultiView runat="server" ID="MultiView" ActiveViewIndex="0">
                    <asp:View runat="server">
                    </asp:View>
                    <asp:View runat="server">
                        <p><img alt="Loading..." src="/global/images/ajax-mini-loader.gif" style="vertical-align: middle;" />&nbsp;Loading...</p>
                    </asp:View>
                    <asp:View runat="server">
                        <asp:GridView runat="server" ID="WarrantyView" OnDataBound="WarrantyView_DataBound" AutoGenerateColumns="false" ItemType="WarrantySystem.Data.ServiceCompany">
                            <Columns>
                                <asp:BoundField HeaderText="Name" DataField="Name" />
                                <asp:BoundField HeaderText="Telephone" DataField="Telephone" />
                                <asp:BoundField HeaderText="Email" DataField="Email" />
                                <asp:BoundField HeaderText="Telephone 24/7" DataField="Telephone247" />
                                <asp:BoundField HeaderText="Email 24/7" DataField="Email247" />
                                <asp:TemplateField HeaderText="Actions">
                                    <ItemTemplate>
                                        <asp:Button runat="server" ID="btnEdit" CommandName="Edit" CommandArgument="<%# Item.ID %>" Text="Edit" />
                                        <asp:Button runat="server" ID="btnDelete" CommandName="Delete" CommandArgument="<%# Item.ID %>" Text="Delete" OnCommand="btnDelete_Command"/>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </asp:View>
                    <asp:View runat="server">
                        <p>Your data could no be loaded at this time.</p>
                    </asp:View>
                </asp:MultiView>
                <asp:Timer runat="server" ID="tmrLoadData" Enabled="true" Interval="1" OnTick="tmrLoadData_Tick" />
            </ContentTemplate>
        </asp:UpdatePanel>

使用GridView的RowCommand事件启动
Edit
Delete
命令

将其添加到GridView标记中

OnRowCommand="WarrantyView_RowCommand"
同时更改
命令名
文本

CommandName="Modify"  // change the name here
CommandName="Remove"  // change the name here
在活动中

protected void WarrantyView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Modify")
    {
       // your edit logic
    }
    if (e.CommandName == "Remove")
    {
       // your delete logic 
    }
}
我确实建议您更改
CommandName
属性的名称。
Edit
更改为
Modify

Delete
更改为可能
Remove

原因是它们是内置的
gridview
命令


注意:确保在所有相关位置也启用了ViewState。这在禁用ViewState时不起作用。

使用GridView的RowCommand事件启动
Edit
Delete
命令

将其添加到GridView标记中

OnRowCommand="WarrantyView_RowCommand"
同时更改
命令名
文本

CommandName="Modify"  // change the name here
CommandName="Remove"  // change the name here
在活动中

protected void WarrantyView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Modify")
    {
       // your edit logic
    }
    if (e.CommandName == "Remove")
    {
       // your delete logic 
    }
}
我确实建议您更改
CommandName
属性的名称。
Edit
更改为
Modify

Delete
更改为可能
Remove

原因是它们是内置的
gridview
命令


注意:确保在所有相关位置也启用了ViewState。这在禁用ViewState的情况下不起作用。

您能给我们看一下您的命令代码吗:编辑和删除。@Jackpetinger,请参阅编辑。没有什么区别,因为它们根本没有被击中-(它在
gridview
中。使用
gridview
@PraveenNambiar的
rowcommand
事件,这对我不起作用,你能提供一个示例用法作为答案吗?请看我的答案……它会起作用的……你必须更改命令名,如下所示。你能给我们看看你的命令代码:Edit和Del吗ete.@JackPettinger,请参见编辑。它们根本没有被击中,所以差别不大!:-(它在
gridview
中。使用
gridview
@PraveenNambiar的
row命令
事件,这对我不起作用,你能提供一个示例用法作为答案吗?请看我的答案…它会起作用的…你必须更改命令名,如下所示。谢谢你提供的额外信息。我不知道EdiGridView使用了t和Delete。不幸的是,这也不起作用。请更新问题中的代码,了解到目前为止您所做的更改。还可以通过删除updatepanel进行快速检查。请参阅答案底部的备注。已排序,答案已被接受。感谢提供其他信息。我不知道使用了Edit和Delete通过GridView。不幸的是,这也不起作用。请更新问题中的代码,了解到目前为止您所做的更改。还可以通过删除updatepanel进行快速检查。请参阅答案底部的我的注释。已排序,答案已接受。