简体   繁体   English

ASP.Net FormView 不会使用 Response.Redirect 代码更新

[英]ASP.Net FormView won't update with Response.Redirect code

I have a fairly simple FormView control I'm using with ASP.Net/C#.我有一个相当简单的 FormView 控件,用于 ASP.Net/C#。 My issue is when I use the code to redirect after the update/edit, the FormView won't actually perform the update, but, it will Redirect.我的问题是当我在更新/编辑后使用代码重定向时,FormView 不会实际执行更新,但是,它会重定向。 I won't post all of the FormView code because it does update when I comment out the Redirect code.我不会发布所有的 FormView 代码,因为当我注释掉重定向代码时它会更新。 I think what I am asking is how to change the code to update while using the Redirect Code?我想我要问的是如何在使用重定向代码时更改要更新的代码? Again, the update works fine when I don't do the Redirect!同样,当我不进行重定向时,更新工作正常! Is it possible the redirect is happening before the update can take place?是否有可能在更新发生之前发生重定向?

Code for Redirect重定向代码

         <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" />
                    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>

Yes...it redirecting before the update.是的...它在更新之前重定向。 Take your redirect out of ItemUpdating and put it in ItemUpdated.将您的重定向从 ItemUpdating 中取出并将其放入 ItemUpdated。

From: DetailsView.ItemUpdatint Event来自: DetailsView.ItemUpdint 事件

DetailsView.ItemUpdating Event DetailsView.ItemUpdate 事件

Occurs when an Update button within a DetailsView control is clicked, but before the update operation.在单击 DetailsView 控件中的更新按钮时发生,但在更新操作之前发生。

DetailsView.ItemUpdated Event DetailsView.ItemUpdated 事件

Occurs when an Update button within a DetailsView control is clicked, but after the update operation.在单击 DetailsView 控件中的更新按钮时发生,但在更新操作之后发生。

DetailsView.ItemUpdated Event DetailsView.ItemUpdated 事件

Your code should look like:您的代码应如下所示:

protected void FormView1_ItemUpdated(Object sender, FormViewUpdateEventArgs e)
{
    Response.Redirect("redirect_main.aspx");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM