C# ASP.Net FormView赢得';t使用响应更新。重定向代码
我在ASP.Net/C中使用了一个相当简单的FormView控件。我的问题是,当我在更新/编辑后使用代码重定向时,FormView实际上不会执行更新,但会重定向。我不会发布所有的FormView代码,因为当我注释掉重定向代码时,它会更新。我想我要问的是,如何在使用重定向代码时将代码更改为更新?同样,当我不执行重定向时,更新工作正常!是否可能在更新发生之前发生重定向 重定向代码C# ASP.Net FormView赢得';t使用响应更新。重定向代码,c#,sql,asp.net,.net,C#,Sql,Asp.net,.net,我在ASP.Net/C中使用了一个相当简单的FormView控件。我的问题是,当我在更新/编辑后使用代码重定向时,FormView实际上不会执行更新,但会重定向。我不会发布所有的FormView代码,因为当我注释掉重定向代码时,它会更新。我想我要问的是,如何在使用重定向代码时将代码更改为更新?同样,当我不执行重定向时,更新工作正常!是否可能在更新发生之前发生重定向 重定向代码 <script runat="server"> protec
<script runat="server">
protected void FormView1_ItemUpdating(Object sender, FormViewUpdateEventArgs e)
{
{
Response.Redirect("redirect_main.aspx");
}
}
</script>
FormView1
<asp:FormView ID="FormView1" runat="server" onitemupdating="FormView1_ItemUpdating" DataKeyNames="req_submitted_key" DataSourceID="SqlDataSource2" DefaultMode="Edit" >
<EditItemTemplate>
req_submitted_key:
<asp:Label ID="req_submitted_keyLabel1" runat="server" Text='<%# Eval("req_submitted_key") %>' />
<br />
Role_job_title:
<asp:TextBox ID="Role_job_titleTextBox" runat="server" Text='<%# Bind("Role_job_title") %>' />
<br />
requestname:
<asp:TextBox ID="requestnameTextBox" runat="server" Text='<%# Bind("requestname") %>' />
<br />
submitted_by_name:
<asp:TextBox ID="submitted_by_nameTextBox" runat="server" Text='<%# Bind("submitted_by_name") %>' />
<br />
Submitted_by_email:
<asp:TextBox ID="Submitted_by_emailTextBox" runat="server" Text='<%# Bind("Submitted_by_email") %>' />
<br />
submitted_date:
<asp:TextBox ID="submitted_dateTextBox" runat="server" Text='<%# Bind("submitted_date") %>' />
<br />
submitted_by_comment:
<asp:TextBox ID="submitted_by_commentTextBox" runat="server" Text='<%# Bind("submitted_by_comment") %>' />
<br />
approved_denied:
<asp:TextBox ID="approved_deniedTextBox" runat="server" Text='<%# Bind("approved_denied") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
受保护的无效FormView1\u项更新(对象发送方,FormViewUpdateEventArgs e)
{
{
重定向(“Redirect_main.aspx”);
}
}
FormView 1
请求提交密钥:
角色\职务\职称:
请求名称:
提交人姓名:
通过电子邮件提交:
提交日期:
提交人提交的意见:
批准或拒绝:
是…它在更新之前重定向。将重定向从ItemUpdated中取出并放入ItemUpdated中
发件人:
DetailsView.ItemUpdate事件
单击DetailsView控件中的更新按钮时发生,
但是在更新操作之前
DetailsView.ItemUpdate事件
单击DetailsView控件中的更新按钮时发生,
但是在更新操作之后
您的代码应该如下所示:
protected void FormView1_ItemUpdated(Object sender, FormViewUpdateEventArgs e)
{
Response.Redirect("redirect_main.aspx");
}
也许我需要再次阅读这篇文章,但我看不到在该页中它解释了如何防止我的问题发生。@user2209864好的。.我更新了答案。…删除重定向并将其放入ItemUpdated。我将尝试一下@user2209864我读到这段代码会有帮助,但我得到了一个异常错误!(不包含异常的定义,如果(e.Exception==null)受保护的void FormView1_ItemUpdating(对象发送方,FormViewUpdateEventArgs e){{{Response.Redirect(“Redirect_main.aspx”);}