Link to home
Start Free TrialLog in
Avatar of Jonathan Mori
Jonathan MoriFlag for United States of America

asked on

How to display a "Record Successfully Inserted" Message on input.

I know this is probably simple, but i can't figure it out for some reason. I just need a little message that says "Record Successfully Submitted" when they input it into the database. I'm not sure how to code this. Here is my InputForm code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc1" TagName="DynDropDown" 
    Src=DynamicDDL.ascx %>
 
<script runat="server">
 
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
</script>
 
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
 
<head runat="server">
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>Submission Form</title>
<style type="text/css">
.style1 {
	font-size: xx-large;
	text-align: center;
}
.style2 {
	font-size: medium;
	text-align: center;
}
    .style3
    {
        width: 100%;
    }
    .style4
    {
        text-align: center;
    }
</style>
</head>
 
<body bgcolor="F8F8FF">
 
<p class="style1">LAND ANALYSIS DATABASE SUBMISSION FORM</p>
<p class="style2"><a href="DatabaseResults.aspx">RESULTS</a></p>
<form id="form1" runat="server" style="border-style: groove; border-width: medium; z-index: auto; width: 1205px; height: 1305px; position: relative; top: 15px; left: -3px">
	<div>
		<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LA_DBASEConnectionString %>" 
            SelectCommand="SELECT * FROM [MainLATable]" 
            DeleteCommand="DELETE FROM [MainLATable] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [MainLATable] ([Rank_Main], [Mapper_Main], [State_Main], [County_Main], [GIS_Ref], [Agmnt_No], [Tract_Nos], [Control_Stmnt], [Problem], [Resolution], [Date_Ini], [Date_Resolved], [Date_update], [GIS_Comments], [Send_Tim]) VALUES (@Rank_Main, @Mapper_Main, @State_Main, @County_Main, @GIS_Ref, @Agmnt_No, @Tract_Nos, @Control_Stmnt, @Problem, @Resolution, @Date_Ini, @Date_Resolved, @Date_update, @GIS_Comments, @Send_Tim)" 
            
            UpdateCommand="UPDATE [MainLATable] SET [Rank_Main] = @Rank_Main, [Mapper_Main] = @Mapper_Main, [State_Main] = @State_Main, [County_Main] = @County_Main, [GIS_Ref] = @GIS_Ref, [Agmnt_No] = @Agmnt_No, [Tract_Nos] = @Tract_Nos, [Control_Stmnt] = @Control_Stmnt, [Problem] = @Problem, [Resolution] = @Resolution, [Date_Ini] = @Date_Ini, [Date_Resolved] = @Date_Resolved, [Date_update] = @Date_update, [GIS_Comments] = @GIS_Comments, [Send_Tim] = @Send_Tim WHERE [ID] = @ID">
			<DeleteParameters>
				<asp:parameter Name="ID" Type="Int32" />
			</DeleteParameters>
			<UpdateParameters>
				<asp:parameter Name="Rank_Main" Type="String" />
				<asp:parameter Name="Mapper_Main" Type="String" />
				<asp:parameter Name="State_Main" Type="String" />
				<asp:parameter Name="County_Main" Type="String" />
				<asp:parameter Name="GIS_Ref" Type="String" />
				<asp:parameter Name="Agmnt_No" Type="String" />
				<asp:parameter Name="Tract_Nos" Type="String" />
				<asp:parameter Name="Control_Stmnt" Type="String" />
				<asp:parameter Name="Problem" Type="String" />
				<asp:parameter Name="Resolution" Type="String" />
				<asp:parameter Name="Date_Ini" Type="DateTime" />
				<asp:parameter Name="Date_Resolved" Type="DateTime" />
				<asp:parameter Name="Date_update" Type="DateTime" />
			    <asp:Parameter Name="GIS_Comments" Type="String" />
                <asp:Parameter Name="Send_Tim" Type="Boolean" />
                <asp:Parameter Name="ID" Type="Int32" />
			</UpdateParameters>
			<InsertParameters>
				<asp:parameter Name="Rank_Main" Type="String" />
				<asp:parameter Name="Mapper_Main" Type="String" />
				<asp:parameter Name="State_Main" Type="String" />
				<asp:parameter Name="County_Main" Type="String" />
				<asp:parameter Name="GIS_Ref" Type="String" />
				<asp:parameter Name="Agmnt_No" Type="String" />
				<asp:parameter Name="Tract_Nos" Type="String" />
				<asp:parameter Name="Control_Stmnt" Type="String" />
				<asp:parameter Name="Problem" Type="String" />
				<asp:parameter Name="Resolution" Type="String" />
				<asp:parameter Name="Date_Ini" Type="DateTime" />
				<asp:parameter Name="Date_Resolved" Type="DateTime" />
			    <asp:Parameter Name="Date_update" Type="DateTime" />
                <asp:Parameter Name="GIS_Comments" Type="String" />
                <asp:Parameter Name="Send_Tim" Type="Boolean" />
			</InsertParameters>
		</asp:SqlDataSource>
		<asp:FormView id="InputForm" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="400px" Width="550px" BorderStyle="Groove" HorizontalAlign="Center">
			<EditItemTemplate>
				Rank (Importance):
				<asp:dropdownlist id="ddlRank" runat="server" DataSourceID="SqlDataSource2" DataTextField="Rank" DataValueField="Rank" SelectedValue='<%# Bind("Rank_Main") %>'>
				</asp:dropdownlist>
				<asp:sqldatasource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:LADBASEConnectionString9 %>" SelectCommand="SELECT [Rank] FROM [LA_Rank]">
				</asp:sqldatasource>
				<br />
				<br />
				Mapper:
				<asp:dropdownlist id="ddlMapper" runat="server" DataSourceID="SqlDataSource3" DataTextField="Mapper" DataValueField="Mapper" SelectedValue='<%# Bind("Mapper_Main") %>'>
				</asp:dropdownlist>
				<asp:sqldatasource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:LADBASEConnectionString9 %>" SelectCommand="SELECT [Mapper] FROM [Mapper]">
				</asp:sqldatasource>
				<br />
				<uc1:DynDropDown ID="DynDropDown1" State='<%# Bind("State_Main") %>' County='<%# Bind("County_Main") %>' runat="server" />
				<br />
				Main:
				<asp:dropdownlist id="ddlState" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="State" DataValueField="State" SelectedValue='<%# Bind("State_Main") %>'>
				</asp:dropdownlist>
				<asp:sqldatasource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:LADBASEConnectionString9 %>" SelectCommand="SELECT [State] FROM [LA_State]">
				</asp:sqldatasource>
				<br />
				<br />
				County:
				<asp:textbox id="TextBox1" runat="server" Text='<%# Bind("County_Main") %>'></asp:textbox>
				<br />
				<br />
				GIS Ref:
				<asp:textbox id="GIS_RefTextBox" runat="server" Text='<%# Bind("GIS_Ref") %>' />
				<br />
				<br />
				Agreement No:
				<asp:textbox id="Agmnt_NoTextBox" runat="server" Text='<%# Bind("Agmnt_No") %>' />
				<br />
				<br />
				Tract No(s):
				<asp:textbox id="Tract_NosTextBox" runat="server" Text='<%# Bind("Tract_Nos") %>' />
				<br />
				<br />
				Control Statement:
				<asp:textbox id="Control_StmntTextBox" runat="server" Text='<%# Bind("Control_Stmnt") %>' />
				<br />
				<br />
				Problem:
				<asp:textbox id="ProblemTextBox" runat="server" Text='<%# Bind("Problem") %>' Height="250px" Width="550px" TextMode="MultiLine" />
				<br />
				<br />
				<br />
				Date Problem Initiated:
				<asp:textbox id="Date_IniTextBox" runat="server" Text='<%# Bind("Date_Ini") %>' />
				<br />
				<br />
				Date GIS Updated:
				<asp:textbox id="Date_UpdateTextBox" runat="server" Text='<%# Bind("Date_Update") %>' />
				<br />
				<br />
				<asp:button id="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
				&nbsp;<asp:button id="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
			</EditItemTemplate>
			<InsertItemTemplate>
				&nbsp;<br />
				<br />
				&nbsp;<table class="style3" border="1">
                    <tr>
                        <td>
                            Rank (Importance):</td>
                        <td>
                            <asp:DropDownList ID="ddlRank" runat="server" DataSourceID="SqlDataSource2" 
                                DataTextField="Rank" DataValueField="Rank" 
                                SelectedValue='<%# Bind("Rank_Main") %>'>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:LA_DBASEConnectionString %>" 
                                SelectCommand="SELECT [Rank] FROM [LA_Rank]"></asp:SqlDataSource>
                        </td>
                        <td>
                            Mapper:</td>
                        <td>
                            <asp:DropDownList ID="ddlMapper" runat="server" DataSourceID="SqlDataSource3" 
                                DataTextField="Mapper" DataValueField="Mapper" 
                                SelectedValue='<%# Bind("Mapper_Main") %>'>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:LA_DBASEConnectionString %>" 
                                SelectCommand="SELECT [Mapper] FROM [Mapper]"></asp:SqlDataSource>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <uc1:DynDropDown ID="DynDropDown1" runat="server" 
                                County='<%# Bind("County_Main") %>' State='<%# Bind("State_Main") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            GIS Ref:</td>
                        <td>
                            <asp:TextBox ID="GIS_RefTextBox" runat="server" Text='<%# Bind("GIS_Ref") %>' />
                        </td>
                        <td>
                            Agreement No:</td>
                        <td>
                            <asp:TextBox ID="Agmnt_NoTextBox" runat="server" 
                                Text='<%# Bind("Agmnt_No") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Tract No(s):</td>
                        <td>
                            <asp:TextBox ID="Tract_NosTextBox" runat="server" 
                                Text='<%# Bind("Tract_Nos") %>' />
                        </td>
                        <td>
                            Control Statement:</td>
                        <td>
                            <asp:TextBox ID="Control_StmntTextBox" runat="server" 
                                Text='<%# Bind("Control_Stmnt") %>' />
                        </td>
                    </tr>
                </table>
                <div class="style4">
                    <br />
                    Problem:</div>
                <table class="style3" border="1">
                    <tr>
                        <td>
                            <asp:TextBox ID="ProblemTextBox" runat="server" Height="250px" 
                                Text='<%# Bind("Problem") %>' TextMode="MultiLine" Width="550px" />
                        </td>
                    </tr>
                </table>
                &nbsp;<table class="style3" border="1">
                    <tr>
                        <td>
                            Date Problem Initiated:<br />
                            (Format: xx/xx/xxxx)</td>
                        <td>
                            <asp:TextBox ID="Date_IniTextBox" runat="server" 
                                Text='<%# Bind("Date_Ini") %>' />
                        </td>
                        <td>
                            Date GIS Updated:</td>
                        <td>
                            <asp:TextBox ID="Date_UpdateTextBox" runat="server" 
                                Text='<%# Bind("Date_Update") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Notify Property Tax Manager:</td>
                        <td>
                            <asp:CheckBox ID="PropManagerTxtBox" runat="server" Checked='<%# Bind("Send_Tim") %>' />
                        </td>
                    </tr>
                </table>
				<br />
				<br />
				<asp:button id="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Submit" />
				&nbsp;<asp:button id="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
			</InsertItemTemplate>
			<ItemTemplate>
				ID:
				<asp:label id="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
				<br />
				Rank_Main:
				<asp:label id="Rank_MainLabel" runat="server" Text='<%# Bind("Rank_Main") %>' />
				<br />
				Mapper_Main:
				<asp:label id="Mapper_MainLabel" runat="server" Text='<%# Bind("Mapper_Main") %>' />
				<br />
				State_Main:
				<asp:label id="State_MainLabel" runat="server" Text='<%# Bind("State_Main") %>' />
				<br />
				County_Main:
				<asp:label id="County_MainLabel" runat="server" Text='<%# Bind("County_Main") %>' />
				<br />
				GIS_Ref:
				<asp:label id="GIS_RefLabel" runat="server" Text='<%# Bind("GIS_Ref") %>' />
				<br />
				Agmnt_No:
				<asp:label id="Agmnt_NoLabel" runat="server" Text='<%# Bind("Agmnt_No") %>' />
				<br />
				Tract_Nos:
				<asp:label id="Tract_NosLabel" runat="server" Text='<%# Bind("Tract_Nos") %>' />
				<br />
				Control_Stmnt:
				<asp:label id="Control_StmntLabel" runat="server" Text='<%# Bind("Control_Stmnt") %>' />
				<br />
				Problem:
				<asp:label id="ProblemLabel" runat="server" Text='<%# Bind("Problem") %>' />
				<br />
				Date_Ini:
				<asp:label id="Date_IniLabel" runat="server" Text='<%# Bind("Date_Ini") %>' />
				<br />
				Date_Resolved:
				<asp:label id="Date_ResolvedLabel" runat="server" Text='<%# Bind("Date_Resolved") %>' />
				<br />
				Date_Update:
				<asp:label id="Date_UpdateLabel" runat="server" Text='<%# Bind("Date_Update") %>' />
				<br />
			</ItemTemplate>
		</asp:FormView>
	</div>
</form>
 
</body>
 
</html>

Open in new window

Avatar of David Robitaille
David Robitaille
Flag of Canada image

in the
InputForm_ItemInserted or SqlDataSource1_ItemInserted
check If e.Exception IsNot Nothing to make sure the insertion dont caused an exception.
Avatar of Jonathan Mori

ASKER

hi thanks, i have this below, but i'm still not having a message show up, am I missing something?
using System;
using System.IO;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Services.Protocols;
using System.Text;
using System.Net;
 
 
 
public partial class Default : System.Web.UI.Page
{
    protected void InputForm_ItemInserted(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception != null)
            Response.Write("Record Inserted Successfully");
        else
            throw e.Exception;
    }
}

Open in new window

Does the code run? (try to put a break point)
Does the data is added to the database?
did you try with SqlDataSource1_ItemInserted?
 
ya, the code seems to be running, the data is added to the database.

I tried both SqlDataSource1_ItemInserted, and InputForm_ItemInserted
ASKER CERTIFIED SOLUTION
Avatar of David Robitaille
David Robitaille
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh ok, i found a good solution here and with your help, thank you!

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.iteminserted.aspx