Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6639807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:35:53+00:00 2026-05-25T23:35:53+00:00

I am using Entity Framework and Telerik RadGrid. I have a table with a

  • 0

I am using Entity Framework and Telerik RadGrid. I have a table with a constraint which throws an exception if a product with a duplicate name is tried as an insert. I am trying to catch the exception in my business layer and it seems to run through the catch block fine but I get an error from the Telerik RadScriptManager

“Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Exception has been thrown by the target of an invocation.”

instead of the Jquery popup that I am expecting with the message “Duplicate Product” Does anyone know what I am doing wrong? does the exception need to behandled in my DAL? but I dont think i should throw BusinessRuleExceptions from somewhere besides the BLL. I have posted the Insert function in my BL class below, if anyone has an idea what might be causing the Jscript error, please let me know, thanks!!

Edit
The Object Data Source TypeName is tied to the Business layer ProductBL
Product BL function Insert_Product is being called from my ObjectDataSource as the Insert function. In the Product.cs code behind class I have a function for Inserting Products where I am passing the product Name (see below), this function has a try catch bloeck..should I be throwing the exception here? I thought it would be right to throw the BusinessRulException in the Business Layer.

Product.CS class (Object Data Source Insert command)

 protected void ODSProducts_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        try
        {

            TextBox txtProductName = (TextBox)ProductsGrid.MasterTableView.GetInsertItem().FindControl("txtProductName");

            ((ACME.DAL.Product)e.InputParameters[0]).Product.product_name = txtProductName.Text;

        }
        catch (Exception ex)
        {
            HTMLError.HtmlError.LogHtmlError(ex, Application["ErrorLog"].ToString());
            throw;
        }
    }

ProductsBL.CS

   public void Insert_Product(Product product)
      {
        try
        {
            repository.Insert_Product(product);
        }
        catch (Exception ex)
        {
            if (ex.GetType().Name == "UpdateException")
            {

               throw new BusinessRuleException("Duplicate Product");
            }

        }
    }

Product.DAL

 public void InsertProduct(Product product)
    {

        context.Products.AddObject(product);

        context.SaveChanges();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:35:53+00:00Added an answer on May 25, 2026 at 11:35 pm

    ok I figured this out after wasting too many hours on this. It seems like Telerik doesnt like me throwing the Business rule exception from the Business Layer class. So I ended up handling the exception instead in the codebehind in the object data source_Inserted event. This is what I did to display the error in a RadAlertWindow from the event.

    enter code here
    protected void ODSProducts_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            if (e.Exception != null)
            {
                if (((e.Exception.InnerException).InnerException).Message.Contains("Cannot insert duplicate key row"))
                {
                    RadWindowManager.RadAlert("Duplicate Product, Enter a new Product", 330, 100, "Insert Error", "");
                    e.ExceptionHandled = true;
                }
            }
        }
    

    I dont like checking the .InnerException.Message.Contains bit but thats the only way I knew how to make sure if the exception was SQL throwing duplicate error on the unique constraint on the field. If someone knows of a more elegant way to do this please share. Hope this helps someone else as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Entity-Framework 4.1 database-first approach. I have a legacy database which every table
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I am using Entity Framework with my website. To improve performance, I have started
I'm using Entity Framework in my project, and I have the problem that, once
I have a problem with the following Linq query using Entity Framework: from o
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I am using Entity Framework from .NET 3.5 I have two tables with 0-1
I'm using entity framework and i have a problem that this dropdown ignores my
Using Entity Framework with MVC2, I have a series of date textboxes, that I
Using Entity Framework I have the fields: o CreatedOn (datetime) o CreatedBy (nvarchar(50)) o

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.