You'll never see your new button added to the intellisense when you create
it dynamically in this fashion. The button only exists at run-time and
therefore cannot be accessed at designtime, especially since it's scope as a
variable is limited to the pageload. Why not add the click event handler at
the same time you are adding the new button control tot he form. You don't
have to have it in the designer to add the click event to it. You can add
the event in the line before you add b to the the form controls, or right
after. I've heard a number or recomendations for setting things like a click
event after you add it to the page's control hierarchy so that it is better
tracked in the viewstate.
Now, your big problem is going to be timing. The real issue here is since
the button isn't created until the page_load event is called you won't be
able to receive a click event if the postback occurs before the control is
recreated. What you'll need to do is experiment with placing the button
creation in an earlier event such as the init or preload. That way they
button will be created before the postback event is called.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Bob" <.wrote in message news:Og**************@TK2MSFTNGP02.phx.gbl...
Hi,
I'm working with VWD and i defined programmatically a button (in
code-behind) with an ID. So I expect to see beside "Page Events" and
"Form1" my button "b1" in order to use the Click event. But it doesnt'
appear. After saving the code-behind file, i only see "Page Events" and
"Form1".
If i define the button declarativally, i see it. But i need to define it
programmatically.
Can anybody tell me how to do? I also tried with Attributes.add but that's
only for client script.
Thanks
Bob
The code:
---------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim b As New Button
b.ID = "b1"
form1.Controls.Add(b)
End Sub