sstoos
asked on
On Demand Loading of a control
I currently have a asp.net page that has an Infragistics control on it. The control's page load event fires before the parent page load event. My problem is that the parent page needs to save data and then set a session variable which passes to the control, but due to the fact that the control loads first, the session variable never gets set. Is there a way to not load the control and call it after the savedata method on the parent page?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok...I'm a little new on this concept. I'm using vb so I assume I declare the control in the declarations as control, right. Then what do you mean by Placeholder1? Also, what is uc1 referencing?
You can declare it as the way I showed.
Then what do you mean by Placeholder1?
--> PlaceHolder1 is WebControl if you BrowsYour WebControl you'll see "PlaceHolder" in them.
--> Drag and drop PlaceHolder1 wherever you want to put your UserControl
UC1
--> UserControl1 is the Name of you Control and uc1 is Object of that control
But, I think the 2nd option will be lot easier to deal with if you can adapt that..
-tusahr
Then what do you mean by Placeholder1?
--> PlaceHolder1 is WebControl if you BrowsYour WebControl you'll see "PlaceHolder" in them.
--> Drag and drop PlaceHolder1 wherever you want to put your UserControl
UC1
--> UserControl1 is the Name of you Control and uc1 is Object of that control
But, I think the 2nd option will be lot easier to deal with if you can adapt that..
-tusahr
ASKER
So if I was to use the second option....sorry to be so dense, but what does "Response.redirect(request .RawURL) do? And this code would reside in the ascx page load???
Response.Redirect : Will Redirect you to URL that is passed as Argument
Request.RawUrl : Will Give you current URL of page.
You need call Response.Redirect( Request.RawUrl ) after you have Set your Session variable.
"the parent page needs to save data and then set a session variable which passes to the control"
--> Set Session Variable and then use Response.Redirct to Re-load page
.. Page_Load(..)
{
if( Session["YourSessionName"] == null )
{
SaveData();
Session["YourSessionName"] = "SetSession";
Response.Redirect( Request.RawUrl );
}
}
ps. You should always check that Session Variable are not null before using them anywhere.
-tushar
Request.RawUrl : Will Give you current URL of page.
You need call Response.Redirect( Request.RawUrl ) after you have Set your Session variable.
"the parent page needs to save data and then set a session variable which passes to the control"
--> Set Session Variable and then use Response.Redirct to Re-load page
.. Page_Load(..)
{
if( Session["YourSessionName"]
{
SaveData();
Session["YourSessionName"]
Response.Redirect( Request.RawUrl );
}
}
ps. You should always check that Session Variable are not null before using them anywhere.
-tushar
ASKER
The only disadvantage that I can see with this, is that the control will still load first and am trying to get around that, if possible.
Alright in that case
- Put PlaceHolder/Panel wherever you want to show UserControl
- After you Set your session add following line:
Dim uc1 As UserControl1 = CType(Page.LoadControl("Us erControl1 .ascx"), UserControl1)
PlaceHolder1.Controls.Add( uc1)
[ Replace UserControl1 with name of your UserControl.
i.e. if your UserControl is Header.ascx then replace "UserControl1" with "Header" ]
-tushar
- Put PlaceHolder/Panel wherever you want to show UserControl
- After you Set your session add following line:
Dim uc1 As UserControl1 = CType(Page.LoadControl("Us
PlaceHolder1.Controls.Add(
[ Replace UserControl1 with name of your UserControl.
i.e. if your UserControl is Header.ascx then replace "UserControl1" with "Header" ]
-tushar
Add this line in your ASPX HTML
<%@ Reference Control = "UserControl1.ascx" %>
And then in code Add this after you initialize sessions
UserControl1 uc1 = (UserControl1) Page.LoadControl("UserCont
PlaceHolder1.Controls.Add(
-tushar