我有一个基本GridView
与CommandField
,它使用CommandField的内置编辑,取消,更新和删除按钮,ButtonType
属性设置为 “图像”(ImageButtons),定义为:为什么没有将__doPostBack()JavaScript添加到GridView中的CommandField更新按钮时呈现为HTML
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false"
OnRowEditing="gv_RowEditing" OnRowCancelingEdit="gv_RowCancelingEdit" OnRowUpdating="gv_RowUpdating" OnRowDeleting="gv_RowDeleting">
<Columns>
<asp:CommandField
ShowEditButton="true" ShowDeleteButton="true" ButtonType="Image"
EditImageUrl="~\Images\Icons\gridView_Edit.png"
CancelImageUrl="~\Images\Icons\gridView_CancelEdit.png"
UpdateImageUrl="~\Images\Icons\gridView_Update.png"/>
</Columns>
为OnRowEditing,OnRowCancelingEdit,OnRowUpdating和OnRowDeleting事件服务器侧C#事件处理程序工作正常和被定义为:
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e) { }
protected void gv_RowEditing(object sender, GridViewEditEventArgs e) { }
protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { }
protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e) { }
当页面被渲染到HTML,在CommandField
的ImageButtons
呈现以下(简化)<input>
标签:
<input type="image" name="ctl00$Body$gv$ctl02$ctl00" src="Images/update.png" alt="Update" style="border-width:0px;">
<input type="image" src="Images/delete.png" alt="Delete" onclick="javascript:__doPostBack('ctl00$Body$gv','Delete$0')" style="border-width:0px;">
<input type="image" src="Images/edit.png" alt="Edit" onclick="javascript:__doPostBack('ctl00$Body$gv','Edit$0')" style="border-width:0px;">
<input type="image" src="Images/cancel.png" alt="Cancel" onclick="javascript:__doPostBack('ctl00$Body$gv','Cancel$0')" style="border-width:0px;">
注:在现实中,只有任编辑/删除或更新/取决于任何时候渲染,取决于GridView是否处于编辑模式。
那么,为什么呈现的更新按钮不使用ASP.NET的__doPostBack JavaScript函数,当删除,编辑和取消按钮呢?
如何处理OnRowUpdating
事件是?
注意:当使用缺省ButtonType
为CommandField
它不渲染__doPostBack,但使用ButtonType="Image"
__doPostBack当不包括在内。
我知道,所有四个按钮不是一次渲染的,我简化了我的示例以求清晰。但是,Update按钮没有附加__doPostBack。 – Brissles
您是否下载了我的简洁示例?你的代码中还有其他东西,因为如果你看看我的例子,你会看到Update上有__doPostback。 –
有趣的是,它显示__doPostBack与默认的CommandField ButtonType,但我的例子显示ButtonType =“图像”,并且不会呈现更新ImageButton的__doPostBack – Brissles