Problem with runat=server

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi grou

my code is simple but not working

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa

Dim MyButton As New System.Web.UI.WebControls.Butto
Me.Controls.Add(MyButton

End Su

What is the reason that this simple code causes an error and how can I fix it

Thank
Joy
 
Please always include include the exact error you have when posting...

For now, my guess would be that you have to add this control inside your
server side form tag...

Patrice

--

Joy said:
Hi group

my code is simple but not working:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 
When you use the Add() method, it adds the control at the end of the page. Try replacing all the code with the following:

Dim l As New Literal
l.Text = "foo"
Me.Controls.Add(l)

Build the page, and view its source. Notice where foo appears, after the final HTML tag. Consider using AddAt(x) or a placeholder instead of Add().

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Back
Top