473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Why OnPreInit unvailable on controls

WT
Hello,

I can't see OnPreInit method for Webcontrols and controls.
Why the method is not similarly called for controls as it is done for Page
Control ?
It is sometime uneasy to initialize SkinID for dynamic controls.
In the past we had the OnInit method of the custom control to initialize
everything, but we can't initialize SkinID in OnPreinit, getting an
exception. And as far as no OnPreInit exists, how to initialize SkinID for
dynamic controls???

Any help welcome, waiting for a correction from MS ?

Thanks
CS

Feb 9 '07 #1
8 6477
Hi CS,

Yes unfortunately PreInit is only available in Page class, it's not
available in Control class.

However, based on my understanding, a control normally is designed to be
used by Page. A control should not hard-code a skin, instead it should let
the Page choose one in Page's PreInit:

#How to: Apply ASP.NET Themes Programmatically
http://msdn2.microsoft.com/en-us/lib...89(vs.80).aspx

You also mentioned "initialize SkinID for dynamic controls", do you mean
that the control is created dynamically? If this is the case, it should be
able to set its SkinID when it's created in Page's PreInit.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 9 '07 #2
WT
Lets say that my constrols are custom controls loaded dynamically fromdb
with loadcontrol.
So where to place the skinID init ?
I have tried to use the PreInit event but unsucessfully ?

CS
"Walter Wang [MSFT]" <wa****@online.microsoft.coma écrit dans le message
de news: jJ**************@TK2MSFTNGHUB02.phx.gbl...
Hi CS,

Yes unfortunately PreInit is only available in Page class, it's not
available in Control class.

However, based on my understanding, a control normally is designed to be
used by Page. A control should not hard-code a skin, instead it should let
the Page choose one in Page's PreInit:

#How to: Apply ASP.NET Themes Programmatically
http://msdn2.microsoft.com/en-us/lib...89(vs.80).aspx

You also mentioned "initialize SkinID for dynamic controls", do you mean
that the control is created dynamically? If this is the case, it should be
able to set its SkinID when it's created in Page's PreInit.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 10 '07 #3
Hi CS,

You could create a public property to wrap the consitituent control's
SkinID and assign this property in Page's PreInit:

WebUserControl.ascx.cs:

public string TextBoxSkinID
{
get { return txt1.SkinID; }
set { txt1.SkinID = value; }
}

Page.aspx.cs:

protected override void OnPreInit(EventArgs e)
{
WebUserControl wuc =
(WebUserControl)LoadControl("~/WebUserControl.ascx");
wuc.TextBoxSkinID = "BlueTheme";
form1.Controls.Add(wuc);

base.OnPreInit(e);
}
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #4
WT
In fact I need to lad the custom controls in Page.OnPreInit ?
They were originally loaded in Page.OnDataBinding.
Problem is OnDatabinding is it called from OpreInit or after ?
CS

"Walter Wang [MSFT]" <wa****@online.microsoft.coma écrit dans le message
de news: FP**************@TK2MSFTNGHUB02.phx.gbl...
Hi CS,

You could create a public property to wrap the consitituent control's
SkinID and assign this property in Page's PreInit:

WebUserControl.ascx.cs:

public string TextBoxSkinID
{
get { return txt1.SkinID; }
set { txt1.SkinID = value; }
}

Page.aspx.cs:

protected override void OnPreInit(EventArgs e)
{
WebUserControl wuc =
(WebUserControl)LoadControl("~/WebUserControl.ascx");
wuc.TextBoxSkinID = "BlueTheme";
form1.Controls.Add(wuc);

base.OnPreInit(e);
}
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 12 '07 #5
WT
In fact my problem is the OndataBinding eventis called during Page_Load.
CS

"WT" <WT@newsgroups.nospama écrit dans le message de news:
u5**************@TK2MSFTNGP03.phx.gbl...
In fact I need to lad the custom controls in Page.OnPreInit ?
They were originally loaded in Page.OnDataBinding.
Problem is OnDatabinding is it called from OpreInit or after ?
CS

"Walter Wang [MSFT]" <wa****@online.microsoft.coma écrit dans le message
de news: FP**************@TK2MSFTNGHUB02.phx.gbl...
>Hi CS,

You could create a public property to wrap the consitituent control's
SkinID and assign this property in Page's PreInit:

WebUserControl.ascx.cs:

public string TextBoxSkinID
{
get { return txt1.SkinID; }
set { txt1.SkinID = value; }
}

Page.aspx.cs:

protected override void OnPreInit(EventArgs e)
{
WebUserControl wuc =
(WebUserControl)LoadControl("~/WebUserControl.ascx");
wuc.TextBoxSkinID = "BlueTheme";
form1.Controls.Add(wuc);

base.OnPreInit(e);
}
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

================================================= =
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights.


Feb 12 '07 #6
Hi CS,

It seems I may have misunderstood something regarding the PreInit event.
It's actually only Page.Theme property can be set in PreInit. Setting
Control.SkinID should be fine in Page_Load or during DataBinding:

<%@ Page Language="C#" Theme="Theme1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
TextBox txt1 = new TextBox();
txt1.Text = "Page_Load";
txt1.SkinID = "BlueTheme";
form1.Controls.Add(txt1);

this.DataBinding += new EventHandler(default2_aspx_DataBinding);
this.DataBind();
}

void default2_aspx_DataBinding(object sender, EventArgs e)
{
TextBox txt1 = new TextBox();
txt1.Text = "DataBinding";
txt1.SkinID = "BlueTheme";
form1.Controls.Add(txt1);
}

</script>
I'm sorry if I may have caused some confusion in my previous replies.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 13 '07 #7
WT
Hello Walter,

So why I get this exception trying to initialize a SkinID:
(this has been solved by initializing SkinID in PreInit for dynamic
controls)

ProcessUnhandledException enter GetLastError:
System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.InvalidOperationException: The 'SkinId' property can only be set in
or before the Page_PreInit event for static controls. For dynamic controls,
set the property before adding it to the Controls collection.
at System.Web.UI.Control.set_SkinID(String value)
at System.Web.UI.WebControls.WebControl.set_SkinID(St ring value)
at AddonNice.UI.WebControls.PortalModuleControl.OnIni t(EventArgs e)
at Ax.WTPageModules.PortalsAdmin.Portals.OnInit(Event Args e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.ControlCollection.Add(Control child)
at System.Web.UI.WebControls.Table.RowControlCollecti on.Add(Control
child)
at Ax.UI.WebControls.DesktopPanes0.CreateControlHiera rchy()
at Ax.UI.WebControls.DesktopPanes0.CreateChildControl s()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.desktopdefault_aspx.ProcessRequest(HttpContext context)
at
System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

"Walter Wang [MSFT]" <wa****@online.microsoft.coma écrit dans le message
de news: tM**************@TK2MSFTNGHUB02.phx.gbl...
Hi CS,

It seems I may have misunderstood something regarding the PreInit event.
It's actually only Page.Theme property can be set in PreInit. Setting
Control.SkinID should be fine in Page_Load or during DataBinding:

<%@ Page Language="C#" Theme="Theme1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
TextBox txt1 = new TextBox();
txt1.Text = "Page_Load";
txt1.SkinID = "BlueTheme";
form1.Controls.Add(txt1);

this.DataBinding += new EventHandler(default2_aspx_DataBinding);
this.DataBind();
}

void default2_aspx_DataBinding(object sender, EventArgs e)
{
TextBox txt1 = new TextBox();
txt1.Text = "DataBinding";
txt1.SkinID = "BlueTheme";
form1.Controls.Add(txt1);
}

</script>
I'm sorry if I may have caused some confusion in my previous replies.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 13 '07 #8
Hi CS,

If you're set a constituent control's SkinID in UserControl's OnInit or
Page_Load event, these events are still fired after you added the
UserControl to page's control tree, therefore you will see the exception.

There're two workarounds:

1) Use a public property to expose the constituent control's SkinID, and
set this property before adding the UserControl to control tree:

WebUserControl wc = (WebUserControl)LoadControl("~/WebUserControl.ascx");
wc.TextBoxSkinID = "BlueTheme";
form1.Controls.Add(wc);

2) If you want to hard-code SkinID for your constituent controls, you could
create a public method to do that and let the Page call this method before
adding the UserControl to control tree:

WebUserControl wc = (WebUserControl)LoadControl("~/WebUserControl.ascx");
wc.SetSkinID();
form1.Controls.Add(wc);

Hope this helps.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 14 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
by: Mark Johnson | last post by:
Sometimes Controls that have been added to a GroupBox do not show up. What I am doing : 1) I am not using the designer, but create all the Controls per hand: groupBoxProdukt_01 = new...
3
by: Roger | last post by:
Hi In a Windows forms application I have 2 forms A and B; Form B inherits from form A. Form A is never displayed and its only purpose is to be inherited from and therefore contains mostly...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
2
by: CAIBird | last post by:
hi, this time, i hit a more specific issue. when i execute the following code, i run into a exception says "RPC server is unvailable!": string path =...
1
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. protected override void OnPreInit(EventArgs e){ if ((bool)session){ this.MasterPageFile = "~/NewMaster.master"; }...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.