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

  • SEARCH
  • Home
  • 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 5956223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:13:35+00:00 2026-05-22T18:13:35+00:00

I have a 7 web pages and a class that declares some properties, event

  • 0

I have a 7 web pages and a class that declares some properties, event and some functions. The object of this class i.e. _ItemSetup is moved into all the pages and same copy is maintained on all the pages. Based on this object of ItemSetup class certain business decisions are taken and values are changed.

public class ItemSetup 
{

    /// <summary>
    /// Raises an event after FK_ITEM_TYPE property has changed.  
    /// PropertyChanged object returns value of FK_ITEM_TYPE before change and after change
    /// </summary>
    public event EventHandler<PropertyChanged> ItemTypeChanged;


    private long fK_ITEM_TYPE;
    /// <summary>
    /// Item type can be-Package, Subassembly, cash and many more.
    /// So each item type will have different behaviour based on which validation changes.
    /// "ItemTypeChanged" event is triggered when this property value is changed.
    /// </summary>
    public long FK_ITEM_TYPE 
    {
        get { return fK_ITEM_TYPE; }
        set 
        {
            if (value == fK_ITEM_TYPE)
                return;
            fK_ITEM_TYPE = value;

            PropertyChanged eOnChanged = new PropertyChanged(null, value);
            if (ItemTypeChanged!= null)
                ItemTypeChanged(this, eOnChanged);
        }
    }
 }

Code behind file for raising an event.

public partial class ItemMaster_Main : System.Web.UI.Page
{

    public ItemSetup _ItemSetup { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        ItemSetup.MenuBarEventAssociation(ItemMenu, SaveInputValues);

        if (!IsPostBack)
        {
            BindDropDown();

            if (Session["ItemSetup"] != null)
            {
                _ItemSetup = Session["ItemSetup"] as ItemSetup;
                //Do something.
            }
            else
            {
                _ItemSetup = new ItemSetup(ItemSetup.OperationMode.Add);
                _ItemSetup.ItemTypeChanged += new EventHandler<PropertyChanged>(_ItemSetup_ItemTypeChanged);

                Session["ItemSetup"] = _ItemSetup;
            }
        }
        _ItemSetup = Session["ItemSetup"] as ItemSetup;
    }

    protected void cmbItemType_SelectedIndexChanged(object sender, EventArgs e)
    {
        _ItemSetup.FK_ITEM_TYPE = long.TryParse(cmbItemType.SelectedValue, out outLong) ? outLong : (long)L_ITEM_TYPE.SelectOne;

        // When I calls this as a functions. It do its work and sets the css.
        //_ItemSetup_ItemTypeChanged(null, null);
    }

    void _ItemSetup_ItemTypeChanged(object sender, PropertyChanged e)
    {
        //Hide or show button based on conditions
        btnNext.Visible = !(_ItemSetup.FK_ITEM_TYPE == (int)AARFID.DataLayer.L_ITEM_TYPE.SelectOne);

        //Hide all controls until Item Type is not selected.           
        if (_ItemSetup.FK_ITEM_TYPE == (long)L_ITEM_TYPE.SelectOne)
            divControlBox.Attributes.Add("style", "display:none;");
        else
            divControlBox.Attributes.Add("style", "display:block;");
    }
}

When the property FK_ITEM_TYPE is set at any point the event _ItemSetup_ItemTypeChanged gets raised and all the code written into the function gets executed. I expected that controls should have been hidden. But it did nothing to the page.

I am not getting the reason why this event is not effecting the page.
When I uncomments the line in function cmbItemType_SelectedIndexChanged
i.e.

//_ItemSetup_ItemTypeChanged(null,
null);

the properties and css gets set and page behaves as expected.

What could be the reason.

EDIT

if i associates event handler ourside IsPostBack then page gets effected as desired but events keeps adding on.

(_ItemSetup.ItemTypeChanged as EventHandler<PropertyChanged>).GetInvocationList()
{System.Delegate[17]}
    [0]: {Method = {Void ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [1]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [2]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [3]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [4]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [5]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [6]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [7]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [8]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [9]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [10]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [11]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [12]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [13]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [14]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [15]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
    [16]: {Method = {Void _ItemSetup_ItemTypeChanged(System.Object, AARFID.DataLayer.PropertyChanged)}}
  • 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-22T18:13:36+00:00Added an answer on May 22, 2026 at 6:13 pm

    With every postback the _ItemSetup instance is losing the correct wiring of its eventhandlers so you have to add them with each page load and remove them on page unload. In short version:

    protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["ItemSetup"] == null)
            {
                _ItemSetup = new ItemSetup();
                Session["ItemSetup"] = _ItemSetup;
            }
    
            _ItemSetup = Session["ItemSetup"] as ItemSetup;
            _ItemSetup.ItemTypeChanged += _ItemSetup_ItemTypeChanged;            
        }
    
    protected void Page_Unload(object sender, EventArgs e)
        {
            _ItemSetup.ItemTypeChanged -= _ItemSetup_ItemTypeChanged;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some web pages which have two frames, with one frame in the
I have several web pages on several different sites that I want to mirror
I have a bunch of ASP.NET web pages (that have a standard layout) that
I have an .Net Froms application that displays web pages through a WebBrowser control.
Problem: I have to support users who need to edit web pages. Some of
I have ASP.NET web pages for which I want to build automated tests (using
I have all the web pages of a website. My task is to change
I have a series of interlinked web pages, and I want to restrict access
The rails books and web pages I've been following have all stuck to very
I'm programming in PHP and would like to create web pages which have email

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.