似乎没有被发射的__doPostBack正确的GridView的标记 [英] Does not appear to be emitting correct GridView markup for __doPostBack

查看:603
本文介绍了似乎没有被发射的__doPostBack正确的GridView的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问<一个href=\"http://stackoverflow.com/questions/4852474/asp-net-gridview-update-button-fires-edit-event-handler\">this关于从在ASP.Net GridView控件一个奇怪的行为(我使用C#)。问题

有关在我的GridView的每一行有一个修改和删除链接。例如编辑有这个的javascript:__ doPostBack('gvwServers','编辑$ 0') - 所以,很显然,服务器是要弄清楚有人点击编辑一行 0 gvwServers 。

很公平。如果我点击编辑链接我得到一个回发,并在GridView重绘与一个更新和取消按钮代替Edit按钮。标准行为。 NOW - 取消按钮有此链接的javascript:__ doPostBack('gvwServers','取消$ 0') - 这正是我所期待取消行 0 gvwServers 的。但更新按钮有的javascript:__ doPostBack('gvwServers $ ctl02 $ ctl00','')。这似乎没有任何意义。这似乎是我的日常的原因来处理更新不会被解雇。

为什么不ASP输出正确的回传参数呢?

我的code可在上面的链接。

 &LT; ASP:GridView控件ID =gvwServers=服务器级=gvwServers
的AutoGenerateColumns =false的OnRowEditing =gvwServers_Edit
onrowcancelingedit =gvwServers_Cancellingonrowdeleting =gvwServers_Deleting
onrowupdated =gvwServers_Updatedonrowupdating =gvwServers_Updating
AutoGenerateEditButton属性=真AutoGenerateDeleteButton =真&gt;&LT;列&GT;
    &LT; ASP:CommandField中ShowEditButton =真/&GT;
    &LT; ASP:CommandField中的ShowDeleteButton =真/&GT;
    &LT; ASP:BoundField的数据字段=intServerID可见=假/&GT;    &LT; ASP:的TemplateField的HeaderText =服务器名称&GT;
        &LT;&ItemTemplate中GT;
            &LT; ASP:标签ID =lblServerName=服务器文本='&LT;%#绑定(改为txtName)%&GT;'&GT;&LT; / ASP:标签&gt;
        &LT; / ItemTemplate中&GT;
        &LT;&EditItemTemplate的GT;
            &LT; ASP:文本框ID =txtServerName_Edit=服务器文本='&LT;%#绑定(改为txtName)%&GT;'&GT;&LT; / ASP:文本框&GT;
        &LT; / EditItemTemplate中&GT;
    &LT; / ASP:的TemplateField&GT;    &LT; ASP:的TemplateField的HeaderText =密钥&GT;
        &LT;&ItemTemplate中GT;
            &LT; ASP:标签ID =lblAppKey=服务器文本='&LT;%#绑定(txtApplicationKey)%&GT;'&GT;&LT; / ASP:标签&gt;
        &LT; / ItemTemplate中&GT;
        &LT;&EditItemTemplate的GT;
            &LT; ASP:文本框ID =txtAppKey_Edit=服务器文本='&LT;%#绑定(txtApplicationKey)%&GT;'&GT;&LT; / ASP:文本框&GT;
        &LT; / EditItemTemplate中&GT;
    &LT; / ASP:的TemplateField&GT;    &LT; ASP:的TemplateField的HeaderText =连接字符串&GT;
        &LT;&ItemTemplate中GT;
            &LT; ASP:标签ID =lblConnString=服务器文本='************'&GT;&LT; / ASP:标签&gt;
        &LT; / ItemTemplate中&GT;
        &LT;&EditItemTemplate的GT;
            &LT; ASP:文本框=服务器ID =txtConnString_EditWIDTH =300像素HEIGHT =100px的文本='&LT;%#绑定(txtConnectionString)%&GT;'的TextMode =多行&GT;&LT; / ASP:文本框&GT;
        &LT; / EditItemTemplate中&GT;
    &LT; / ASP:的TemplateField&GT;&LT; /列&GT;
&LT; / ASP:GridView的&GT;


解决方案

不知道你期待/没有发生什么。我把你的GridView code和使用您的code中的其他链接的后面。我加在每个处理程序的Response.Write,似乎按预期运行。

 公共类项目
{
    公众诠释intServerID {搞定;组; }
    公共字符串txtName的{搞定;组; }
    公共字符串txtApplicationKey {搞定;组; }
    公共字符串txtConnectionString {搞定;组; }
}保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    项目项目=新的项目();
    item.intServerID = 1;
    item.txtName =苹果;
    item.txtApplicationKey =橙色;
    item.txtConnectionString =测试;    清单&LT;项目&GT;项目=新的List&LT;项目&GT;();
    items.Add(项目);    gvwServers.DataSource =物品;
    gvwServers.DataBind();
}保护无效gvwServers_Edit(对象发件人,GridViewEditEventArgs E)
{
    的Response.Write(编辑);
    gvwServers.EditIndex = e.NewEditIndex;
    gvwServers.DataBind();
}
保护无效gvwServers_Updated(对象发件人,GridViewUpdatedEventArgs E)
{
    的Response.Write(更新);
    gvwServers.DataBind();
}保护无效gvwServers_Updating(对象发件人,GridViewUpdateEventArgs E)
{
    的Response.Write(更新);
    gvwServers.DataBind();
}
保护无效gvwServers_Deleting(对象发件人,GridViewDeleteEventArgs E)
{
    的Response.Write(删除);
    gvwServers.DataBind();
}
保护无效gvwServers_Cancelling(对象发件人,GridViewCancelEditEventArgs E)
{
    的Response.Write(取消);    e.Cancel =真;
    gvwServers.EditIndex = -1;
    gvwServers.DataBind();
}

I asked this question regarding a strange behaviour from a GridView control in ASP.Net (I'm using C#).

For each row in my GridView there is an an 'Edit' and 'Delete' link. The edit for example has this javascript:__doPostBack('gvwServers','Edit$0') - So obviously the server is going to figure out someone has clicked to edit row 0 of gvwServers.

Fair enough. If I click the Edit link I get a postback and the GridView is redrawn with the Edit button replaced with an 'Update' and 'Cancel' button. Standard behaviour. NOW - The 'Cancel' button has this link javascript:__doPostBack('gvwServers','Cancel$0') - just what I would expect Cancel row 0 of gvwServers. BUT The Update button has javascript:__doPostBack('gvwServers$ctl02$ctl00',''). This appears to not make any sense. And this appears to be the cause of my routine to handle Update not being fired.

Why is ASP not outputting the correct postback arguments?

My code is available at the link above.

<asp:GridView ID="gvwServers" runat="server" class="gvwServers"  
AutoGenerateColumns="false"  OnRowEditing="gvwServers_Edit" 
onrowcancelingedit="gvwServers_Cancelling" onrowdeleting="gvwServers_Deleting" 
onrowupdated="gvwServers_Updated" onrowupdating="gvwServers_Updating"
AutoGenerateEditButton=true AutoGenerateDeleteButton=true>

<columns>
    <asp:CommandField  ShowEditButton="true" />
    <asp:CommandField  ShowDeleteButton="true" /> 
    <asp:BoundField DataField="intServerID" visible="false" />

    <asp:TemplateField HeaderText = "Server Name">
        <ItemTemplate>
            <asp:Label ID="lblServerName" runat="server" Text='<%# Bind("txtName") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtServerName_Edit" runat="server" Text='<%# Bind("txtName") %>'></asp:TextBox>
        </EditItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField  HeaderText = "Key">
        <ItemTemplate>
            <asp:Label ID="lblAppKey" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtAppKey_Edit" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:TextBox>
        </EditItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField  HeaderText = "Connection String">
        <ItemTemplate>
            <asp:Label ID="lblConnString" runat="server" Text='************'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox runat="server" ID="txtConnString_Edit" Width="300px" Height="100px" Text='<%# Bind("txtConnectionString")%>' TextMode="MultiLine" ></asp:TextBox>
        </EditItemTemplate>
    </asp:TemplateField>

</columns>
</asp:GridView> 

解决方案

Not sure what you're expecting/not happening. I took your gridview code and used your code behind in the other link. I added a Response.Write in each handler and it seems to run as expected.

public class Item
{
    public int intServerID { get; set; }
    public string txtName { get; set; }
    public string txtApplicationKey { get; set; }
    public string txtConnectionString { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
    Item item = new Item();
    item.intServerID = 1;
    item.txtName = "Apple";
    item.txtApplicationKey = "Orange";
    item.txtConnectionString = "Test";

    List<Item> items = new List<Item>();
    items.Add(item);

    gvwServers.DataSource = items;
    gvwServers.DataBind();
}

protected void gvwServers_Edit(object sender, GridViewEditEventArgs e)
{
    Response.Write("Edit");
    gvwServers.EditIndex = e.NewEditIndex;
    gvwServers.DataBind();
}
protected void gvwServers_Updated(object sender, GridViewUpdatedEventArgs e)
{
    Response.Write("Updated");
    gvwServers.DataBind();
}

protected void gvwServers_Updating(object sender, GridViewUpdateEventArgs e)
{
    Response.Write("Updating");
    gvwServers.DataBind();
}
protected void gvwServers_Deleting(object sender, GridViewDeleteEventArgs e)
{
    Response.Write("Delete");
    gvwServers.DataBind();
}
protected void gvwServers_Cancelling(object sender, GridViewCancelEditEventArgs e)
{
    Response.Write("Cancel");

    e.Cancel = true;
    gvwServers.EditIndex = -1;
    gvwServers.DataBind();
}

这篇关于似乎没有被发射的__doPostBack正确的GridView的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆