Solved

asp.net - last event that fires on a page

Posted on 2013-05-14
3
314 Views
Last Modified: 2013-05-16
In this code snippet I am loading a control at runtime.

"ptg"


I try to call a public method of the control  (  "HideFrame"  ) which turns some <div> tags invisible, because under this circumstance, I don't want them to show.

It fails because I think the HTML for the "ptg" control is not full rendered.



  Reo.ContentControls.PostponedTaskGridPopup ptg = ((Reo.ContentControls.PostponedTaskGridPopup)LoadControl("~/ContentControls/PostponedTaskGridPopup.ascx"));


                    ptg.FillVariablesThroughPassedInData(assetTaskIdSid, this.AssetIdSid, "normal");

                    

                    Table t = new Table();
                    TableRow trName = new TableRow();
                    TableRow trRole = new TableRow();
                    TableRow trDate = new TableRow();
                    TableRow trLink = new TableRow();


                    t.Rows.Add(trName);
                    t.Rows.Add(trDate);
                    t.Rows.Add(trRole);
                    t.Rows.Add(trLink);


                    TableCell tdName = new TableCell();
                    TableCell tdRole = new TableCell();
                    TableCell tdDate = new TableCell();
                    TableCell tdLink = new TableCell();

                    TableCell tdPostpone = new TableCell();

                    tdPostpone.RowSpan = 4;

                    trName.Cells.Add(tdName);
                    trName.Cells.Add(tdPostpone);
                    trRole.Cells.Add(tdRole);
                    trDate.Cells.Add(tdDate);
                    trLink.Cells.Add(tdLink);


                    tdName.Controls.Add(lbl);

                    tdPostpone.Controls.Add(ptg);









/////////// THIS FAILS //////////////////////
                    ptg.HideFrame();

Open in new window





 public void HideFrame()
        {
            //hide surrounding divs and layout stuff
            
            HtmlGenericControl fh = ((HtmlGenericControl)FindControl("frame_header"));
            HtmlGenericControl fr = ((HtmlGenericControl)FindControl("frame"));
            fh.Visible = false;
            fr.Attributes.CssStyle.Clear();
        }

Open in new window




//fails
fh.Visible = false

fails because fh is null.


I think it is because the page rendering is not far enough along to be able to hide the <div>.

So my question is - how can I know when it is safe to hide the control (the div)
0
Comment
Question by:knowlton
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 total points
ID: 39166964
This may help you out. It explains the  page life cycle in asp.net.

http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx

The PreRender event may be the one that you need.

"Occurs after the Control object is loaded but prior to rendering."

http://msdn.microsoft.com/en-us/library/system.web.ui.control.prerender%28v=vs.100%29.aspx
0
 
LVL 5

Author Comment

by:knowlton
ID: 39168402
I tried PreRender.

I also tried Page_Unload, which I think is the last event  (but I think it fires after the page has been sent to the client, so is of no use)

Is there something **right before** Page_Unload, but after Pre_Render?  Like a "Post_Render" ??

I'll take a closer look at the page life cycle.
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 39172064
I eventually solved this with jQuery:


 $('div[id*="_divPostponedTaskGrid"]').each(function () {

            var tablecount = $(this).children('div').children().size();
           
            if (tablecount == 0) {
                $(this).closest('#frame').hide();
            }
            else {
                $(this).closest('#frame').css('background-image', 'none');
            }
        });

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now