Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

click event does not occur in webusercontrol

0 views
Skip to first unread message

Bisser Milanov

unread,
Jun 16, 2003, 4:23:00 PM6/16/03
to
1. I create a WebControlLibrary called wcl
2. I add the following code to the library
Private WithEvents m_btn As New Button()

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
m_btn.RenderControl(output)
End Sub

Private Sub wcl_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Init
m_btn.Text = "test button"
Me.Controls.Add(m_btn)
End Sub

3. I create a test project called testwcl
4. In the test project I add WebUserControl1
5. I drag the wcl control from the toolbox to the WebUserControl
6. In the Default WebForm of the test project I put a placeholder - ph. And
a button - Button1

Here comes the trick.
If I put the following code
ph.Controls.Add(LoadControl("WebUserControl1.ascx"))

in the event Page_Load of the WebForm and I run the project - it works.
Which is I see the WebUserControl on the WebForm and if I press the button
constructed from the library I receive the event Click in the library.

But if I move the above mentioned piece of code in the event Page_PreRender
or Button1_Click then it does not work. Which is I run the project press the
button constructed from the library and the click event does not occur. WHY?

So actually it appears that it works properly only if I load the control in
the Load event. But I can't do that because I want to add different
webusercontrol at runtime. And in runtime if I have a combobox from which to
select which control to be loaded and do the load on bombo_click the I don't
receive the button_click events in the library!!!

Any suggestions?

Simon Storr

unread,
Jul 14, 2003, 5:52:47 AM7/14/03
to
I have EXACTLY the same problem - its a catch 22 which I've not yet found an
answer to :o( You can't seem to attach events in PreRender (in fact it only
seems to work if you Add the control in PageLoad, which as you say is too
early... Anyone from Microsoft care to shed any light on the problem? It is
bringing our development to a complete halt :o(

thanks,

Simon

"Bisser Milanov" <b...@bm.bm> wrote in message
news:#iRLhUEN...@TK2MSFTNGP12.phx.gbl...

0 new messages