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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:03:53+00:00 2026-05-12T20:03:53+00:00

I have a web page with a GridView. The GridView contains a list of

  • 0

I have a web page with a GridView. The GridView contains a list of Question objects. Each Question has a QuestionType. When the user clicks on the Question control, an Ajax modal popup appears containing a Dialog custom web control. The Dialog web control is designed to encapsulate a child custom web control together with OK and Cancel buttons. In this scenario, the child control is a Question custom control that represents the selected Question. The exact type of the Question control is not known until a row in the GridView is clicked.

To sum up the page hierarchy:

  • Page
  • GridView containing questions (declared in the .aspx markup, fires
    an event when a row is clicked)
  • Panel linked to AJAX modal popup extender (declared in the .aspx
    markup)
  • Dialog control (declared in the .aspx markup)
  • Question control (created dynamically within the Dialog
    control, type not known until
    Question selection is made)
  • OK button (created dynamically within the Dialog control)
  • Cancel button (created dynamically within the Dialog
    control)

When the user clicks the OK button in the Dialog, I want to be able to get at the contents of the Dialog from the containing page. (There is code in the various Question controls that validates the answer and a property in the Dialog that exposes the answer to the containing page.)

I have been having large amounts of trouble in getting this to work.

I have been googling for hours and all articles about custom web controls state that you need to create child controls within the OnInit override. However, in my scenario, the Dialog OnInit method is called before GridView fires its row clicked event, meaning I can’t create the Question control because I don’t know the target type.

I can make it at least show the dynamic Question control if I move code that creates it to a later point in the lifecycle of the Dialog e.g. RenderContents. However, this is not correct according to all the articles and useless anyway because the control is still not available when the OK button in the Dialog is clicked (as the dialog is hidden and RenderContents will never be called).

So, I’m asking the ASP.NET guys on here how this is supposed to be done? I’m not looking for the code; just strategy. What is the correct way to set this up? The aim is a dialog that contains a dynamically created control whose type depends on the selected row in the GirdView and that can be accessed by the containing page after a postback.

Any tips would be greatly appreciated.

UPDATE

I added logging and the order of events firing after the grid is clicked is as follows:

  • Page ctor
  • Dialog ctor
  • Dialog OnInit
  • Page OnInit
  • Page CreateChildControls
  • Dialog CreateChildControls
  • Page OnLoad
  • Dialog OnLoad
  • Page OnContactorComplianceQuestionSelected
  • Dialog RenderContents

I only know what type of control the Dialog is supposed to contain after Page OnContactorComplianceQuestionSelected.

  • 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-12T20:03:54+00:00Added an answer on May 12, 2026 at 8:03 pm

    Don’t create dynamic controls in OnInit – that is way too early in the lifecycle and will take you down an unpleasant rabbit hole. Instead:

    • In your Click event handler (late in the lifecycle) store in the ViewState or Session the QuestionID or whatever other information you need to determine which controls to create. Then add the controls. So when the page comes back to the user, the controls will be present.

    • In CreateChildControls check to see if the ViewState contains a QuestionID and if so, re-add the controls from there. So when the user re-submits the page, this time around in the lifecycle, you can reconstitute the control tree as it should be.

    So something like:

    private void AddQuestionControls(int questionID)
    {
        //create and add question controls
    }
    
    void Handle_Click(object sender, EventArgs e)
    {
        //determine question ID
        ViewState["QuestionID"] = questionID;
        AddQuestionControls(questionID);
    }
    
    override void CreateChildControls()
    {
        if(ViewState["QuestionID"] != null)
        {
            AddQuestionControls(Convert.ToInt32(ViewState["QuestionID"]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 241k
  • Answers 241k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That's Yes and Yes. You'll have to use the 2003… May 13, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer The latest version supports Transparent Windows. I don't use that… May 13, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer Your approach is reasonable, however, I'm not sure why you… May 13, 2026 at 7:24 am

Related Questions

Using aspnet, c# 3.5, developing in vs2008. Using IE7. I have a web page
I have a web app(ASP.NET 2.0 using C#) that I am working on. In
I have a web application where I am getting data from an oracle database
I have a aspx page that has a GridView with a datasource of an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.