I’m trying to redirect after a successful insert command on a formview. Here’s what I have:
Detail.aspx:
<asp:FormView id="formview1"...datasourceid="detailsSQLDS">
<InsertItemTemplate>
DateOfService:
<asp:TextBox ID="DateOfServiceTextBox" runat="server"
Text='<%# Bind("DateOfService") %>' />
<br />
InsurancePrimary:
<asp:TextBox ID="InsurancePrimaryTextBox" runat="server"
Text='<%# Bind("InsurancePrimary") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
</InsertItemTemplate>
</asp:FOrmView>
....
<asp:SqlDataSource ID="detailsSQLDS" runat="server"
ConnectionString="..."
InsertCommandType="StoredProcedure"
InsertCommand="usp_Insert"
>
Code Behind:
protected void formview1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
Response.Redirect( "List.aspx?mrn=" + Request.QueryString["mrn"] );
}
The insert works fine, but not the redirect. I don’t think it’s firing the function formview1_ItemInserted(….). Is there a way to tell the formview to fire this function after a successful insert, or some other way of doing this? Thanks!
Ah, I found it. I needed to add the OnItemInserted=”formview1_ItemInserted” declaration to my formview. So i’ve got:
Now it works great.