Click here to Skip to main content
15,883,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Currently this is the code in my .cs file; notice it does 'throw new NotImplementedException();', so it is ment to throw this exception when a duplicate field is being entered from my form into the database. The field name is 'Awards_Title'

public partial class NewPages_Create_New_Awards : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["NEW"] != null)
        {
            //Label1.Text += Session["NEW"].ToString();
            //Label2.Text = Request.QueryString.ToString(); - QueryString taking information from another page.
        }
        else
        {
            Response.Redirect("~/NewPages/Admin Pages/NewLogin.aspx");
        }

        SqlDataSource1.Inserted += new SqlDataSourceStatusEventHandler(SqlDataSource1_Inserted);
    }

    void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        throw new NotImplementedException();

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Form data saved.')", true);
        }
    }
}


This is the code that is currently in my aspx file

<asp:TemplateField HeaderText="Title *" SortExpression="Awards_Title">
    <EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Awards_Title") %>'></asp:TextBox></EditItemTemplate>
    <InsertItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Awards_Title") %>'></asp:TextBox></InsertItemTemplate>
     <ItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Bind("Awards_Title") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>


So what I am want to do is when NotImplementedException() is thrown .. there should be a message beside Awards_Title text box (TextBox1) saying 'Award Title has already been created please use a unique name'.

Can someone please help me with this it is a very urgent!!
Posted
Updated 4-Sep-13 1:15am
v3

1 solution

You can add 'try catch' block to the code
C#
try{
   throw new NotImplementedException();
}catch(Exception ex){
   lblErrorMessage.Text=ex.Message;
}

so, you can catch the error message and print it on a label.


Still the better version is to check the duplication before submit button. Using ajax call on the Textbox's lost focus (change) event. It will take some time and will be little complex.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900