Reputation: 893
i have a simple input form, want to include a thank you message after a user inserts a data. my OnInserting="SqlDataSource1_Inserted"
method is not working. i'm new to programming so no judgment :/
error message:
CS0123: No overload for 'SqlDataSource1_Inserted' matches delegate 'System.Web.UI.WebControls.SqlDataSourceCommandEventHandler'
Line 36: </p>
Line 37: <p>
Line 38: <asp:SqlDataSource ID="SqlDataSource1" runat="server"
Line 39: ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>"
Markup:
<body>
<form id="form1" runat="server">
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px"
DefaultMode="Insert" CellPadding="4"
GridLines="None">
<Fields>
<asp:BoundField DataField="email" HeaderText="text_test" SortExpression="text_test" />
<asp:CommandField ShowInsertButton="True"/>
</Fields>
</asp:DetailsView>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:VZConnectionString %>"
InsertCommand="INSERT INTO [test] ([text_test]) VALUES (@text_test)"
OnInserting="SqlDataSource1_Inserted"
ProviderName="<%$ ConnectionStrings:TESTConnectionString.ProviderName %>"
SelectCommand="SELECT text_test FROM test" >
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="text_test" />
</InsertParameters>
</asp:SqlDataSource>
</p>
</form>
</body>
</html>
Code-behind:
protected void SqlDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.AffectedRows > 0)
{
Response.Write("<script language='javascript'> { alert('a message');}</script>");
}
}
Upvotes: 0
Views: 1185
Reputation: 94645
@MG,
You need to handle Inserted event but look at your code, it is inserting
...
oninserted="SqlDataSource1_Inserted"
..
Upvotes: 1
Reputation: 21
It'll probably be the OnInserted event that you need, not OnInserting (in your aspx).
This is raised post Insert.
Turbo
Upvotes: 2
Reputation: 1194
Remove curly brackets on your response message as
Response.Write("<script language='javascript'> alert('a message');</script>");
Upvotes: 1