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 4069458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:30:13+00:00 2026-05-20T16:30:13+00:00

Alright…this is a bit of a complex problem so hopefully I can explain it

  • 0

Alright…this is a bit of a complex problem so hopefully I can explain it properly.

I have a user control which I am dynamically loading in my page_load event via a method (see below). The user control contains a gridview and a label. A key piece of information has to do with how to get around the convenient feature of gridviews not rendering when their datasource is empty. In my user control I add some hidden rows so that the grids will render and the user can see just the headers (if the situation calls for it).

The nomControl is an asp:Panel on the parent page which will hold the user controls. The dsRefinedProductsNomInfo is a strongly typed dataset.

private void LoadCycleControls()
    {
        var dsRefinedProductsNomInfo = Session[REFINED_PRODUCT_NOMINATION_INFO] as RefinedProductsNomInfo;

        if (dsRefinedProductsNomInfo == null)
        {
            return;
        }

        int permittedCycles = dsRefinedProductsNomInfo.NOS_MONTH.Count == 0 ? 0: dsRefinedProductsNomInfo.NOS_MONTH[0].PERMITTED_CYCLES;

        for (int cycle = 1; cycle <= permittedCycles; cycle++ )
        {
            var control = LoadControl("~/CustomControl/RefinedProductNominationCycleControl.ascx");
            nomContent.Controls.Add(control);

            var nomControl = control as RefinedProductNominationCycleControl;

            if (nomControl == null)
            {
                return;
            }

            nomControl.CycleNumber = cycle;
            nomControl.ID = "control_" + cycle;
            nomControl.CycleTitle = "Cycle " + cycle;

            nomControl.GridDataSource = dsRefinedProductsNomInfo.REFINED_PRODUCT_NOS_CYCLE_INFO;
        }
    }

Now when a user adds a row to the grid they click a plus button. In the button javascript click event I make an ajax call to a page method.

 var options = {
    type: "POST",
    url: "RefinedProductNomination.aspx/AddNomCycleLineItem",
    data: "{'id':'" + tableRow.attr("id") + "',\
            'isPlug':'" + isPlug + "',\
            'sequenceNbr':'" + sequenceNbr + "',\
            'receiptLocationId':'" + receiptLocationId + "',\
            'materialTypeId':'" + materialId + "',\
            'shipperId':'" + shipperId + "',\
            'tankId':'" + tankId + "',\
            'deliveryLocationId':'" + deliveryLocationId + "',\
            'volume':'" + volume + "',\
            'cycle':'" + cycle + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) {
        if (response.d != "") {
            if (response.d == "-1000") {

                var messageContainer = tableRow.parents("div").siblings("div #messageSummary");
                messageContainer.empty()
                var message = $("<span></span>").append("There has been an issue accepting the row please try again.");

                messageContainer.append(message);
                message.fadeOut(10000, "linear");

            }
            else {
                ConvertToReadOnlyRow(tableRow, response.d);
            }
        }
    }
};
//Call the PageMethods
$.ajax(options); 

The page method then retrieves the dataset from the cache and adds the new row the user created. This all works fine and I can save to the database via an asp:button and handling it’s click event.

My issue is after the the user clicks the save button and everything is rendered my grid shows the rows I added to make sure just the headers show up. In my save button click event I am removing these added rows so they don’t get persisted and then saving and then added again once we load the user control. Initially this seems like the right place to handle this but after figuring out the order of events it would appear I was wrong.

So my question. Can anyone suggest how I should be handling my events so that my rendered grid is up to date and not showing these hidden rows. I have a feeling I am just doing things in the wrong place/order but this is my first real swim in the deep end of the asp.net pool. If any more information would be helpful let me know.

Thank you in advance for any help.

  • 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-20T16:30:14+00:00Added an answer on May 20, 2026 at 4:30 pm

    Well I think I have solved my own problem. Essentially what I have done is this:

    1. On parent page_load I reload controls so that they show up on the screen.

    protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                LoadCycleControls();
                return;
            }
    
            RetrieveParameters();
            LoadRefinedNominationInfo();
            LoadLookupLists();
            LoadCycleControls();
        }
    

    2. On control page_load I check IsPostBack. If it’s true I just return.

    protected void Page_Load(object sender, EventArgs e)
        {
            if(IsPostBack)
            {
                return;
            }
    
            BindData();
            cycleNumber.Value = _cycleNumber.ToString();
        }
    

    3. On parent save button click, which caused the post back, I do my normal save logic. After that is complete I iterate over all the controls I created set their data source to the updated dataset. In my control I exposed a method called BindData() which I then call.

     protected void BtnSaveClick(object sender, EventArgs e)
        {
            SaveRefinedProductNosInfo();
    
            var dataSet = RefinedProductsNomInfoCache;
    
            if (dataSet == null)
            {
                return;
            }
    
            foreach (var nomControl in nomContent.Controls.OfType<RefinedProductNominationCycleControl>())
            {
                nomControl.GridDataSource = dataSet.REFINED_PRODUCT_NOS_CYCLE_INFO;
                nomControl.BindData();
            }
        }
    

    Now even though I am slightly new at this, it feels a little dirty which probably means I am not doing things quite right still so if someone actually knows whether I am doing this right or not cares to comment that would be great 🙂

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

Sidebar

Related Questions

Alright, I have a table of tasks this table has a foreign key which
Alright so here is the question. I have a user class which contains a
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, i have read many different views on how to do this with no
Alright, here is my problem i'm trying to solve. I have an index page
Alright so i have been working on this Dynamic load of a spinner from
Alright. I have several queries <?php // Make a MySQL Connection mysql_connect(mm.hostname.net, user, pass)
Alright. Hopefully this will be my last post about the download manager I am
Alright, I am trying to accomplish this: When a user clicks a button that

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.