ItemInserted event in FormView

Joined
Sep 21, 2007
Messages
1
Reaction score
0
Hi all,

I'm only one week into using ASP.NET so please forgive me if this question is annoying or if the answer is obvious. I'm simply trying insert three data fields into a database and just after they are inserted I want to redirect the user to another url. The data goes into the database just fine, but I'm not redirected to another url afterwards. Could someone take a look at my code and see if you have a suggestion? Many thanks.



<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs)
Response.Redirect("http://www.hotmail.com")
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ProductId" DataSourceID="SqlDataSource1" DefaultMode="Insert" BorderColor="#C00000" BorderStyle="Solid" BorderWidth="1px" CellPadding="10" HorizontalAlign="Center">
<InsertItemTemplate>
CategoryId::<br />
<asp:TextBox ID="CategoryIdTextBox" runat="server" Text='<%# Bind("CategoryId") %>'></asp:TextBox><br /><br />
ProductName:<br />
<asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>'></asp:TextBox><br /><br />
ProductPrice:<br />
<asp:TextBox ID="ProductPriceTextBox" runat="server" Text='<%# Bind("ProductPrice") %>'></asp:TextBox><br /><br /><br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:Button>
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:Button>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ContosoMagicConnectionString1 %>"
InsertCommand="INSERT INTO [Products] ([CategoryId], [ProductName], [ProductPrice]) VALUES (@CategoryId, @ProductName, @ProductPrice)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Products]">
<InsertParameters>
<asp: Parameter Name="CategoryId" Type="Int32" />
<asp: Parameter Name="ProductName" Type="String" />
<asp: Parameter Name="ProductPrice" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top