473,396 Members | 1,872 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,396 software developers and data experts.

How to detect when a Component is added to a WebForm

Hello
I have made a component (MyWebForm) that inherits Page. This component
have a method called 'ComponentAdded' that shows a msgbox if it is in
design mode:

Public Class MyWebForm
Inherits System.Web.UI.Page

Public Sub ComponentAdded()
If ((Not Me.Site Is Nothing) AndAlso (Me.Site.DesignMode)) Then
MsgBox("Method ComponentAdded")
End If
End Sub
End Class

I have another component (MyCotrol) that inherits WebControl, that
execute ComponentAdded method when it is added in MyWebForm in design
mode:

<Designer(GetType(DesignerMyCotrol)), ToolboxData("<{0}:MyCotrol
runat=server></{0}:MyCotrol>")> _
Public Class MyCotrol
Inherits WebControl
End Class

Public Class DesignerMyCobtrol
Inherits System.Web.UI.Design.ControlDesigner

Private control As IurisTextBox

Public Overrides Sub OnSetParent()
Try
control = CType(MyBase.Component, MyControl)
If (control.Page.GetType().Name = "MyWebForm") Then
CType(control.Page, MyWebForm).ComponentAdded()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Overrides Function GetDesignTimeHtml() As String
Return "My Control"
End Function
End Class
I want that when MyControl is added in MyWebForm, excute the
ComponentAdded method.
This code not works very well. When MyControl is added, ComponentAdded
method show an exception saying that some object has not been
inicialized.
But if I save the aspx, close it, and open again, the ComponentAdded
method show the msgbox well.
I think that OnSetParent is not the right method to put this code, but
I haven't find any other. Is there any event that execute when a
control is added in a webform?

Thanks
David
Nov 19 '05 #1
0 968

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

Similar topics

1
by: Shawn B. | last post by:
Greetings, If I drop more than one component (custom component) onto a WebForm, is there a way (inside the Component) to identify the instance of the class? For example, Most controls/components...
2
by: julk | last post by:
hi im kind of new to C#. i am doing a Ritch text editor dll, for a webform that im going to need. the components runs fine it does all it need to do, and exposes all the properties i need it to...
1
by: Lauchlan M | last post by:
Hi. I followed the steps suggested below . . . Say I created my component in the namespace "cld.aspnet.components" - where (filepath) would I look for the dll to add in to the toolbox, and...
9
by: Stan | last post by:
Here is my scenario: Web server ------------ Framework 1.1 Application proxy for the serviced component Component server ------------------- Framework 1.0
4
by: A Traveler | last post by:
Hello all, I have a control i wrote which inherits from asp:label. It worked fine. It extends asp:label with a "For" property which implements the "for" attribute of an html label tag (yes i...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
4
by: Dst | last post by:
This is what i'm trying to do: I'm porting a windows app to a web app. I have a webform which will edit some data stored in a database. The data needs to be locked in the database, while editing....
14
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I tried a google search but could not find anything. I am trying to cause one webpage to reload when a second web page is closed. The second webpage loads data into a session variable and when...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.