473,719 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Button Programatically - Doesn’t anyone have an answer???

I have strip-mined, strip-searched, and completely exhausted the
Internet (up to the 30th page on Google, with 100 results per page!!),
all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE
TO PROGRAMMATICALL Y ADD A BUTTON TO A DYNAMICALLY CREATED PAGE.

Or, to be more precise, why it is impossible to have an onClick sub
respond to that button’s Click event.

My main page has only one line:

<%@ page inherits="TeamM etz" src="default.vb " language="VB"
contenttype="te xt/html" responseencodin g="utf-8" %>

That’s it. Nothing more. Now that we have that out of the way, let’s
look at my code-behind.

I have created it so that the Page On_Load creates the header HTML (from
<html> to <body>) and the footer HTML (from </body> to </html>). Inside
these two parts sits the [If Not IsPostBack] portion that allows a
“first load” to proceed smoothly. This first load calls the LoadIntro(),
which pulls data from the db, and populates both a preview section as
well as a form (that is, the form is populated with the db contents, so
that they can be edited). When the button is pressed, what is *supposed*
to happen, is that a sub (the UpdateIntro() sub) *should* be called. The
UpdateIntro() sub is *supposed* to update the db with any changed
contents, and then re-call the LoadIntro() sub to re-populate the page.

What I have discovered is that no matter what I do, IT IS IMPOSSIBLE TO
SET A DYNAMICALLY CREATED BUTTON TO CALL A SUB. That is, I have tried
every trick in the book to have the button call the UpdateIntro() sub,
without success. I have tried [AddHandler submit.Click, AddressOf
UpdateIntro] when creating the button, I have also tried [Handles
submit.Click] when setting the UpdateIntro() sub.

NOTHING WORKS, as the UpdateIntro() sub FAILS TO BE SUCCESSFULLY CALLED.

Here is my Code-behind:

Imports System
Imports System.Configur ation
Imports System.Data
Imports System.Data.Ole Db
'Imports System.Drawing
'Imports System.Drawing. Imaging
'Imports System.IO
'Imports System.Web.Secu rity
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H TMLControls

Public Class TeamMetz
Inherits Page
Dim vbCrLf As String = Microsoft.Visua lBasic.vbCrLf
Dim strYear As String = DateTime.Now.Ye ar.ToString()
Dim strWarning As String = vbCrLf & " <p>Have you <a
href=""/rules.aspx"">re ad the rules</a> for adding content? Do you know
how to <a href=""/formatting.aspx "">properly format text</a>?</p>" & vbCrLf
Dim myForm As New HTMLForm
Dim myConn As New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )

Protected Sub Page_Load(sende r As Object, e As EventArgs)
Dim strURL as String = Request.RawURL. ToString()
Dim strDO as String = Request.QuerySt ring("do")
Dim intID as Integer = Request.QuerySt ring("id")
Dim strP as String = Request.QuerySt ring("parent")
Dim strC as String = Request.QuerySt ring("child")
Dim strG as String = Request.QuerySt ring("gchild")
Dim intE as Integer = Request.QuerySt ring("entry")
Controls.Add(Ne w LiteralControl( "<?xml version=""1.0""
encoding=""UTF-8""?>" & vbCrLf & "<!DOCTYPE html PUBLIC ""-//W3C//DTD
XHTML 1.1//EN""" & vbCrLf & "
""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">" & vbCrLf & "<html
xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" >" & vbCrLf & "
<head>" & vbCrLf & " <title>Team Metz Admin</title>" & vbCrLf & "
<meta name=""robots"" content=""none" " />" & vbCrLf & " <meta
name=""author"" content=""René Kabis, Kabis.NET - Technology Solutions
Consulting"" />" & vbCrLf & " <meta name=""generato r"" content=""A
Text Editor - The only way to code!"" />" & vbCrLf & " <meta
name=""copyrigh t"" content=""1998 - " & strYear & ", Larry Metz and Team
Metz Real Estate."" />" & vbCrLf & " <meta
name=""MSSmartT agsPreventParsi ng"" content=""true" " />" & vbCrLf & "
<meta http-equiv=""imageto olbar"" content=""no"" />" & vbCrLf & "
<meta http-equiv=""Content-language"" content=""en"" />" & vbCrLf & "
<meta http-equiv=""Content-type"" content=""text/html; charset=utf-8""
/>" & vbCrLf & " <meta http-equiv=""Content-Script-Type""
content=""text/javascript"" />" & vbCrLf & " <meta
http-equiv=""Content-Style-Type"" content=""text/css"" />" & vbCrLf &
" <link type=""text/css"" rel=""styleshee t"" media=""all""
href=""/css/global.css"" />" & vbCrLf & " <link type=""text/css""
rel=""styleshee t"" media=""all"" href=""/css/calendar-win2k-1.css""
title=""win2k-1"" />" & vbCrLf & " <script type=""text/javascript""
src=""/js/popup.js""><" & "/script>" & vbCrLf & " <script
type=""text/javascript"" src=""/js/countdown.js""> <" & "/script>" &
vbCrLf & "<!-- Web Standards Compliance Patch for Microsoft Browsers
-->" & vbCrLf & "<!--[if lt IE 7]>" & vbCrLf & " <script
src=""/js/IE7_0_9/ie7-standard-p.js"" type=""text/javascript""><" &
"/script>" & vbCrLf & "<![endif]-->" & vbCrLf & " </head>" & vbCrLf &
" <body>" & vbCrLf & " <div id=""body"">" & vbCrLf & " <div
id=""head"">" & vbCrLf & " <h1><a href=""/default.aspx""
title=""return to the main index"" rel=""home"">Te am Metz
Admin</a></h1>" & vbCrLf & " </div>" & vbCrLf & " <div
id=""content""> " & vbCrLf))
If Not IsPostBack Then
Select Case strDo
Case "add"
Case "edit"
Case "delete"
Case "intro"
LoadIntro()
Case Else
Controls.Add(Ne w LiteralControl( " <h2>Welcome</h2>" &
strWarning & " <p>Please choose a task from the following list:</p>"
& vbCrLf & " <ul>" & vbCrLf & " <li><a
href=""/default.aspx?do =add"">Add Data</a> to the database</li>" &
vbCrLf & " <li><a href=""/default.aspx?do =edit"">Edit Data</a> in
the database</li>" & vbCrLf & " <li><a
href=""/default.aspx?do =intro"">Edit Intro</a> on the front page</li>" &
vbCrLf & " </ul>"))
End Select
End If
Controls.Add(Ne w LiteralControl( vbCrLf & " </div>" & vbCrLf &
" <div id=""foot"">" & vbCrLf & " <address>All Contents are
Copyright © 1998 - " & strYear & " Larry Metz and Team Metz</address>" &
vbCrLf & " <div>" & vbCrLf & " <a
href=""http://validator.w3.or g/check/referer/"" rel=""external" "><img
src=""/images/xhtml.png"" class=""footimg "" alt=""Valid XHTML 1.1""
/></a>" & vbCrLf & " <a
href=""http://jigsaw.w3.org/css-validator/validator?uri=h ttp://admin.getmetz.c om/css/global.css""
rel=""external" "><img src=""/images/css.png"" class=""footimg ""
alt=""Valid CSS 2.0"" /></a>" & vbCrLf & " <a
href=""http://dean.edwards.na me/IE7/intro/"" rel=""external" "><img
src=""/images/ie7.png"" class=""footimg "" alt=""Standards Compliance
Plugin for Internet Explorer"" /></a>" & vbCrLf & " <a
href=""http://www.mozilla.com/"" rel=""external" "><img
src=""/images/firefox.png"" class=""footimg "" alt=""Get Firefox!""
/></a>" & vbCrLf & " <a href=""http://www.mozilla.com/""
rel=""external" "><img src=""/images/thunderbird.png "" class=""footimg ""
alt=""Get Thunderbird!"" /></a>" & vbCrLf & " </div>" & vbCrLf &
" </div>" & vbCrLf & " </div>" & vbCrLf & " </body>" & vbCrLf &
"</html>"))
End Sub

Sub LoadIntro()
Controls.Add(Ne w LiteralControl( " <h2>Edit Intro</h2>" & strWarning))
myForm.ID = "myForm"
Controls.Add(my Form)
Dim myCmd as New OleDbCommand("S ELECT [Comment] FROM [tblIntro]",
myConn)
myConn.Open()
myForm.Controls .Add(New LiteralControl( " <p>This is what is
currently in the Database:</p>" & vbCrLf & " <blockquote>" & vbCrLf &
" <p>" & FormatData(myCm d.ExecuteScalar ()) & "</p>" & vbCrLf & "
</blockquote>" & vbCrLf & " <p>Use the form below to edit the
contents of the database and submit the changes:</p>" & vbCrLf & "
<div class=""center" ">" & vbCrLf & " "))
Dim textarea As New TextBox
textarea.id = "IntroComme nt"
textarea.Text = myCmd.ExecuteSc alar()
textarea.Rows = "8"
textarea.Column s = "80"
textarea.TextMo de = TextBoxMode.Mul tiLine
textarea.Wrap = true
myForm.Controls .Add(textarea)
myForm.Controls .Add(New LiteralControl( "<br />" & vbCrLf & " "))
Dim submit As New Button
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
myForm.Controls .Add(submit)
myForm.Controls .Add(New LiteralControl( vbCrLf & " </div>" & vbCrLf))
myConn.Close()
End Sub
Private Sub UpdateIntro(sen der As Object, e As System.EventArg s)
Dim myCmd as New OleDbCommand("U PDATE tblIntro SET
[Comment]=@Comment", myConn)
myConn.Open()
myCmd.CommandTy pe = CommandType.Tex t
myCmd.Parameter s.Add("@Comment ", OleDbType.LongV arWChar).Value =
RepChar(Request .Form("IntroCom ment"))
myCmd.ExecuteNo nQuery()
myConn.Close()
LoadIntro()
End Sub

Function FormatDate(sIte m as Object) as String
Return String.Format(" <p class=""small"" >Posted: <i>{0:dddd, dd MMMMM,
yyyy}</i></p>", sItem)
End Function
Function FormatData(sIte m) as String
FormatData=sIte m.Replace(vbcrl f,"</p>" & vbCrLf & "
<p>").Replace ("","<b>").Replac e("","</b>").Replace( "","<i>").Replac e("","</i>").Replace(" </p>"
& vbCrLf & " <p>
  • </p>" & vbCrLf & " <p>[item]","</p>" &
    vbCrLf & " <ul>" & vbCrLf & " <li>").Replace( "</p>" & vbCrLf
    & " <p>[item]","</li>" & vbCrLf & " <li>").Replace( "</p>" &
    vbCrLf & " <p>
","</li>" & vbCrLf & " </ul>" & vbCrLf)
End Function
Function RepChar(sItem) as String
RepChar=sItem.R eplace("'","’ ").Replace( " & ", " &amp;
").Replace("<", "&lt;").Replace (">","&gt;")
End Function

End Class
Mar 14 '06 #1
9 2780
wow what a mess!

but to be more helpful... I couldn't see where your <form> tag was at
on that page...

asp.net controls have to be contained within a form tag. example:

<form id="form1" runat="server">
-- your asp.net controls and content--
</form>

I couldn't see a form tag in there anywhere, it seems kind of odd to do
things that way, any particular reason why you didn't just render the
html in the aspx page instead of the vb page?

Mar 14 '06 #2
I believe I already suggested for this problem, to investigate a scenario
such as (and it looks like your code confirms this) :
- LoadIntro is called only when you don't postback
- remember that the page is created *each* time the HTTP requests hits your
server

As a result the button doesn't have any more its handler (and is perhaps not
even recreated at all). Make sure that the control are always created (with
their handler). Also I don't have the exact info but double check also the
control lifecycle to make sure that the control is created before events
wiring is done (else the ASP.NET infrastructure might well not automatically
call the server side click event if the button is not created yet). From the
top of my head, init would be the preferred event for dynamically created
controls...

If all else fails, try to a simple page that just always creates the
control. It should work, and from this test bed, you should easily be able
to experiment to find out the possible remaining differences and the best
strategy...

Good luck.

--
Patrice

"Neo Geshel" <go****@geshel. org> a crit dans le message de
news:OsDRf.1437 74$B94.71430@pd 7tw3no...
I have strip-mined, strip-searched, and completely exhausted the
Internet (up to the 30th page on Google, with 100 results per page!!),
all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE
TO PROGRAMMATICALL Y ADD A BUTTON TO A DYNAMICALLY CREATED PAGE.

Or, to be more precise, why it is impossible to have an onClick sub
respond to that button's Click event.

My main page has only one line:

<%@ page inherits="TeamM etz" src="default.vb " language="VB"
contenttype="te xt/html" responseencodin g="utf-8" %>

That's it. Nothing more. Now that we have that out of the way, let's
look at my code-behind.

I have created it so that the Page On_Load creates the header HTML (from
<html> to <body>) and the footer HTML (from </body> to </html>). Inside
these two parts sits the [If Not IsPostBack] portion that allows a
"first load" to proceed smoothly. This first load calls the LoadIntro(),
which pulls data from the db, and populates both a preview section as
well as a form (that is, the form is populated with the db contents, so
that they can be edited). When the button is pressed, what is *supposed*
to happen, is that a sub (the UpdateIntro() sub) *should* be called. The
UpdateIntro() sub is *supposed* to update the db with any changed
contents, and then re-call the LoadIntro() sub to re-populate the page.

What I have discovered is that no matter what I do, IT IS IMPOSSIBLE TO
SET A DYNAMICALLY CREATED BUTTON TO CALL A SUB. That is, I have tried
every trick in the book to have the button call the UpdateIntro() sub,
without success. I have tried [AddHandler submit.Click, AddressOf
UpdateIntro] when creating the button, I have also tried [Handles
submit.Click] when setting the UpdateIntro() sub.

NOTHING WORKS, as the UpdateIntro() sub FAILS TO BE SUCCESSFULLY CALLED.

Here is my Code-behind:

Imports System
Imports System.Configur ation
Imports System.Data
Imports System.Data.Ole Db
'Imports System.Drawing
'Imports System.Drawing. Imaging
'Imports System.IO
'Imports System.Web.Secu rity
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H TMLControls

Public Class TeamMetz
Inherits Page
Dim vbCrLf As String = Microsoft.Visua lBasic.vbCrLf
Dim strYear As String = DateTime.Now.Ye ar.ToString()
Dim strWarning As String = vbCrLf & " <p>Have you <a
href=""/rules.aspx"">re ad the rules</a> for adding content? Do you know
how to <a href=""/formatting.aspx "">properly format text</a>?</p>" & vbCrLf
Dim myForm As New HTMLForm
Dim myConn As New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )

Protected Sub Page_Load(sende r As Object, e As EventArgs)
Dim strURL as String = Request.RawURL. ToString()
Dim strDO as String = Request.QuerySt ring("do")
Dim intID as Integer = Request.QuerySt ring("id")
Dim strP as String = Request.QuerySt ring("parent")
Dim strC as String = Request.QuerySt ring("child")
Dim strG as String = Request.QuerySt ring("gchild")
Dim intE as Integer = Request.QuerySt ring("entry")
Controls.Add(Ne w LiteralControl( "<?xml version=""1.0""
encoding=""UTF-8""?>" & vbCrLf & "<!DOCTYPE html PUBLIC ""-//W3C//DTD
XHTML 1.1//EN""" & vbCrLf & "
""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">" & vbCrLf & "<html
xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" >" & vbCrLf & "
<head>" & vbCrLf & " <title>Team Metz Admin</title>" & vbCrLf & "
<meta name=""robots"" content=""none" " />" & vbCrLf & " <meta
name=""author"" content=""Ren Kabis, Kabis.NET - Technology Solutions
Consulting"" />" & vbCrLf & " <meta name=""generato r"" content=""A
Text Editor - The only way to code!"" />" & vbCrLf & " <meta
name=""copyrigh t"" content=""1998 - " & strYear & ", Larry Metz and Team
Metz Real Estate."" />" & vbCrLf & " <meta
name=""MSSmartT agsPreventParsi ng"" content=""true" " />" & vbCrLf & "
<meta http-equiv=""imageto olbar"" content=""no"" />" & vbCrLf & "
<meta http-equiv=""Content-language"" content=""en"" />" & vbCrLf & "
<meta http-equiv=""Content-type"" content=""text/html; charset=utf-8""
/>" & vbCrLf & " <meta http-equiv=""Content-Script-Type""
content=""text/javascript"" />" & vbCrLf & " <meta
http-equiv=""Content-Style-Type"" content=""text/css"" />" & vbCrLf &
" <link type=""text/css"" rel=""styleshee t"" media=""all""
href=""/css/global.css"" />" & vbCrLf & " <link type=""text/css""
rel=""styleshee t"" media=""all"" href=""/css/calendar-win2k-1.css""
title=""win2k-1"" />" & vbCrLf & " <script type=""text/javascript""
src=""/js/popup.js""><" & "/script>" & vbCrLf & " <script
type=""text/javascript"" src=""/js/countdown.js""> <" & "/script>" &
vbCrLf & "<!-- Web Standards Compliance Patch for Microsoft Browsers
-->" & vbCrLf & "<!--[if lt IE 7]>" & vbCrLf & " <script
src=""/js/IE7_0_9/ie7-standard-p.js"" type=""text/javascript""><" &
"/script>" & vbCrLf & "<![endif]-->" & vbCrLf & " </head>" & vbCrLf &
" <body>" & vbCrLf & " <div id=""body"">" & vbCrLf & " <div
id=""head"">" & vbCrLf & " <h1><a href=""/default.aspx""
title=""return to the main index"" rel=""home"">Te am Metz
Admin</a></h1>" & vbCrLf & " </div>" & vbCrLf & " <div
id=""content""> " & vbCrLf))
If Not IsPostBack Then
Select Case strDo
Case "add"
Case "edit"
Case "delete"
Case "intro"
LoadIntro()
Case Else
Controls.Add(Ne w LiteralControl( " <h2>Welcome</h2>" &
strWarning & " <p>Please choose a task from the following list:</p>"
& vbCrLf & " <ul>" & vbCrLf & " <li><a
href=""/default.aspx?do =add"">Add Data</a> to the database</li>" &
vbCrLf & " <li><a href=""/default.aspx?do =edit"">Edit Data</a> in
the database</li>" & vbCrLf & " <li><a
href=""/default.aspx?do =intro"">Edit Intro</a> on the front page</li>" &
vbCrLf & " </ul>"))
End Select
End If
Controls.Add(Ne w LiteralControl( vbCrLf & " </div>" & vbCrLf &
" <div id=""foot"">" & vbCrLf & " <address>All Contents are
Copyright 1998 - " & strYear & " Larry Metz and Team Metz</address>" &
vbCrLf & " <div>" & vbCrLf & " <a
href=""http://validator.w3.or g/check/referer/"" rel=""external" "><img
src=""/images/xhtml.png"" class=""footimg "" alt=""Valid XHTML 1.1""
/></a>" & vbCrLf & " <a
href=""http://jigsaw.w3.org/css-validator/validator?uri=h ttp://admin.getmetz
..com/css/global.css""
rel=""external" "><img src=""/images/css.png"" class=""footimg ""
alt=""Valid CSS 2.0"" /></a>" & vbCrLf & " <a
href=""http://dean.edwards.na me/IE7/intro/"" rel=""external" "><img
src=""/images/ie7.png"" class=""footimg "" alt=""Standards Compliance
Plugin for Internet Explorer"" /></a>" & vbCrLf & " <a
href=""http://www.mozilla.com/"" rel=""external" "><img
src=""/images/firefox.png"" class=""footimg "" alt=""Get Firefox!""
/></a>" & vbCrLf & " <a href=""http://www.mozilla.com/""
rel=""external" "><img src=""/images/thunderbird.png "" class=""footimg ""
alt=""Get Thunderbird!"" /></a>" & vbCrLf & " </div>" & vbCrLf &
" </div>" & vbCrLf & " </div>" & vbCrLf & " </body>" & vbCrLf &
"</html>"))
End Sub

Sub LoadIntro()
Controls.Add(Ne w LiteralControl( " <h2>Edit Intro</h2>" & strWarning))
myForm.ID = "myForm"
Controls.Add(my Form)
Dim myCmd as New OleDbCommand("S ELECT [Comment] FROM [tblIntro]",
myConn)
myConn.Open()
myForm.Controls .Add(New LiteralControl( " <p>This is what is
currently in the Database:</p>" & vbCrLf & " <blockquote>" & vbCrLf &
" <p>" & FormatData(myCm d.ExecuteScalar ()) & "</p>" & vbCrLf & "
</blockquote>" & vbCrLf & " <p>Use the form below to edit the
contents of the database and submit the changes:</p>" & vbCrLf & "
<div class=""center" ">" & vbCrLf & " "))
Dim textarea As New TextBox
textarea.id = "IntroComme nt"
textarea.Text = myCmd.ExecuteSc alar()
textarea.Rows = "8"
textarea.Column s = "80"
textarea.TextMo de = TextBoxMode.Mul tiLine
textarea.Wrap = true
myForm.Controls .Add(textarea)
myForm.Controls .Add(New LiteralControl( "<br />" & vbCrLf & " "))
Dim submit As New Button
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
myForm.Controls .Add(submit)
myForm.Controls .Add(New LiteralControl( vbCrLf & " </div>" & vbCrLf))
myConn.Close()
End Sub
Private Sub UpdateIntro(sen der As Object, e As System.EventArg s)
Dim myCmd as New OleDbCommand("U PDATE tblIntro SET
[Comment]=@Comment", myConn)
myConn.Open()
myCmd.CommandTy pe = CommandType.Tex t
myCmd.Parameter s.Add("@Comment ", OleDbType.LongV arWChar).Value =
RepChar(Request .Form("IntroCom ment"))
myCmd.ExecuteNo nQuery()
myConn.Close()
LoadIntro()
End Sub

Function FormatDate(sIte m as Object) as String
Return String.Format(" <p class=""small"" >Posted: <i>{0:dddd, dd MMMMM,
yyyy}</i></p>", sItem)
End Function
Function FormatData(sIte m) as String
FormatData=sIte m.Replace(vbcrl f,"</p>" & vbCrLf & "
<p>").Replace ("","<b>").Replac e("","</b>").Replace( "","<i>").Re pla
ce("
","</i>").Replace(" </p>"
& vbCrLf & " <p>
  • </p>" & vbCrLf & " <p>[item]","</p>" &
    vbCrLf & " <ul>" & vbCrLf & " <li>").Replace( "</p>" & vbCrLf
    & " <p>[item]","</li>" & vbCrLf & " <li>").Replace( "</p>" &
    vbCrLf & " <p>
","</li>" & vbCrLf & " </ul>" & vbCrLf)
End Function
Function RepChar(sItem) as String
RepChar=sItem.R eplace("'","'") .Replace(" & ", " &amp;
").Replace("<", "&lt;").Replace (">","&gt;")
End Function

End Class
Mar 14 '06 #3
nevermind, i see it now... it's the "myform" control. Sorry...

Mar 14 '06 #4
Neo,

I have the idea that somebody is hacking the newsgroups at the moment.
A search on Herfried in this newsgroups gives 69 results, I am sure that it
is not the correct amount of messages Herfried has done.

Button gives me 4 results, I saw this starting on sunday.

I am sure that this sample of mine has been more times in these dotnet
newsgroups.

\\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim mybutton As Button
Dim i As Integer
For i = 0 To New Date().DaysInMo nth _
(New Date().Year, New Date().Month) - 1
mybutton = New Button
mybutton.BackCo lor = Drawing.Color.W hite
mybutton.Text = (i + 1).ToString
mybutton.Width = New Unit(30)
Me.Panel1.Contr ols.Add(mybutto n)
AddHandler mybutton.Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.Panel1.Contr ols.Add(New LiteralControl( "<BR>"))
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArg s)
Dim mylabel As New Label
Me.Panel1.Contr ols.Add(New LiteralControl( "<BR><BR>") )
Me.Panel1.Contr ols.Add(mylabel )
mylabel.Text = "The day is: " & DirectCast(send er, Button).Text
End Sub
///

I will place it tomorrow on our website.
I hope this helps,

Cor
Mar 14 '06 #5
I have created a dramatically cut-down version of the example I wish to
demonstrate. This example fails to function as it should. As I look
through the code, I fail to see what might be going wrong, but the
evidence speaks for itself: the submit button fails to properly call the
UpdateIntro() sub.

Main Page:

<%@ page inherits="TeamM etz" src="test1.vb" language="VB"
contenttype="te xt/html" responseencodin g="utf-8" %>

Code-Behind (test1.vb):

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H TMLControls

Public Class TeamMetz
Inherits Page
Dim vbCrLf As String = Microsoft.Visua lBasic.vbCrLf
Dim myForm As New HTMLForm
Dim textarea As New TextBox
Dim submit As New Button

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Controls.Add(Ne w LiteralControl( "<?xml version=""1.0""
encoding=""UTF-8""?>" & vbCrLf & "<!DOCTYPE html PUBLIC ""-//W3C//DTD
XHTML 1.1//EN""" & vbCrLf & "
""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">" & vbCrLf & "<html
xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" >" & vbCrLf & "
<head>" & vbCrLf & " <title>Test</title>" & vbCrLf & "</head>" &
vbCrLf & " <body>" & vbCrLf & " <div>"))
If Not IsPostBack Then
LoadIntro()
End If
Controls.Add(Ne w LiteralControl( vbCrLf & " </div>" & vbCrLf & "
</body>" & vbCrLf & "</html>"))
End Sub

Private Sub LoadIntro()
myForm.ID = "myForm"
Controls.Add(my Form)
textarea.id = "IntroComme nt"
textarea.Rows = "8"
textarea.Column s = "80"
textarea.TextMo de = TextBoxMode.Mul tiLine
textarea.Wrap = true
myForm.Controls .Add(textarea)
myForm.Controls .Add(New LiteralControl( "<br />" & vbCrLf & " "))
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
myForm.Controls .Add(submit)
End Sub
Private Sub UpdateIntro(sen der As Object, e As EventArgs)
Controls.Add(Ne w LiteralControl( "<p>" &
Request.Form("I ntroComment") & "</p>"))
End Sub
End Class

TIA.
...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 14 '06 #6
As others have said - you need to add all the dynamic controsl *EVERY* time
the page loads.

Remove the 'If Not IsPostback Then' statement. This means LoadInto will
always get called.

"Neo Geshel" <go****@geshel. org> wrote in message
news:um******** ******@TK2MSFTN GP12.phx.gbl...
I have created a dramatically cut-down version of the example I wish to
demonstrate. This example fails to function as it should. As I look
through the code, I fail to see what might be going wrong, but the
evidence speaks for itself: the submit button fails to properly call the
UpdateIntro() sub.

Main Page:

<%@ page inherits="TeamM etz" src="test1.vb" language="VB"
contenttype="te xt/html" responseencodin g="utf-8" %>

Code-Behind (test1.vb):

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H TMLControls

Public Class TeamMetz
Inherits Page
Dim vbCrLf As String = Microsoft.Visua lBasic.vbCrLf
Dim myForm As New HTMLForm
Dim textarea As New TextBox
Dim submit As New Button

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Controls.Add(Ne w LiteralControl( "<?xml version=""1.0""
encoding=""UTF-8""?>" & vbCrLf & "<!DOCTYPE html PUBLIC ""-//W3C//DTD
XHTML 1.1//EN""" & vbCrLf & "
""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">" & vbCrLf & "<html
xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" >" & vbCrLf & "
<head>" & vbCrLf & " <title>Test</title>" & vbCrLf & "</head>" &
vbCrLf & " <body>" & vbCrLf & " <div>"))
If Not IsPostBack Then
LoadIntro()
End If
Controls.Add(Ne w LiteralControl( vbCrLf & " </div>" & vbCrLf & "
</body>" & vbCrLf & "</html>"))
End Sub

Private Sub LoadIntro()
myForm.ID = "myForm"
Controls.Add(my Form)
textarea.id = "IntroComme nt"
textarea.Rows = "8"
textarea.Column s = "80"
textarea.TextMo de = TextBoxMode.Mul tiLine
textarea.Wrap = true
myForm.Controls .Add(textarea)
myForm.Controls .Add(New LiteralControl( "<br />" & vbCrLf & " "))
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
myForm.Controls .Add(submit)
End Sub
Private Sub UpdateIntro(sen der As Object, e As EventArgs)
Controls.Add(Ne w LiteralControl( "<p>" &
Request.Form("I ntroComment") & "</p>"))
End Sub
End Class

TIA.
....Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* "I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours." *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* "Anyone who believes in Intelligent Design ("creationis m") is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* "Intelligen t Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms." - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that "A nymphomaniac is a woman [who is] as
obsessed with sex as the average man." Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********

Mar 14 '06 #7
Marina Levit [MVP] wrote:
As others have said - you need to add all the dynamic controsl *EVERY* time
the page loads.

Remove the 'If Not IsPostback Then' statement. This means LoadInto will
always get called.


But that is also the problem... I only want loadintro() loaded on the
first load. In this test example, I don't want it loaded on the
postback. How do I overcome that?

TIA
...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 14 '06 #8
Cor Ligthert [MVP] wrote:
Neo,

I have the idea that somebody is hacking the newsgroups at the moment.
A search on Herfried in this newsgroups gives 69 results, I am sure that it
is not the correct amount of messages Herfried has done.

Button gives me 4 results, I saw this starting on sunday.

I am sure that this sample of mine has been more times in these dotnet
newsgroups.

\\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim mybutton As Button
Dim i As Integer
For i = 0 To New Date().DaysInMo nth _
(New Date().Year, New Date().Month) - 1
mybutton = New Button
mybutton.BackCo lor = Drawing.Color.W hite
mybutton.Text = (i + 1).ToString
mybutton.Width = New Unit(30)
Me.Panel1.Contr ols.Add(mybutto n)
AddHandler mybutton.Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.Panel1.Contr ols.Add(New LiteralControl( "<BR>"))
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArg s)
Dim mylabel As New Label
Me.Panel1.Contr ols.Add(New LiteralControl( "<BR><BR>") )
Me.Panel1.Contr ols.Add(mylabel )
mylabel.Text = "The day is: " & DirectCast(send er, Button).Text
End Sub
///

I will place it tomorrow on our website.


I hope this helps,

Cor



Adding Handles MyBase.Load to the Page_Load causes the contents of the
page to appear twice. That is, the entire contents of the Page_Load is
rendered twice... so when I do a view source in the browser, I see two
copies of the correct source code, one after another.

...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 14 '06 #9
I didn't read through the code carefully enough to see what else is going on
in that code. Maybe you need to split that method out into 2 methods.

All I know is that you *MUST* re-add the button and its event handler after
the postback. You need to do this every time the page loads - not just the
first time.

So maybe you need to restructure your code, but one way or another the
button and its handler need to be always added if you expect your code to
work.

"Neo Geshel" <go****@geshel. org> wrote in message
news:OM******** *****@TK2MSFTNG P10.phx.gbl...
Marina Levit [MVP] wrote:
As others have said - you need to add all the dynamic controsl *EVERY*
time the page loads.

Remove the 'If Not IsPostback Then' statement. This means LoadInto will
always get called.


But that is also the problem... I only want loadintro() loaded on the
first load. In this test example, I don't want it loaded on the
postback. How do I overcome that?

TIA
....Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* "I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours." *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* "Anyone who believes in Intelligent Design ("creationis m") is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* "Intelligen t Design, on the other hand, has no evidence at all; not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms." - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that "A nymphomaniac is a woman [who is] as
obsessed with sex as the average man." Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 14 '06 #10

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

Similar topics

16
3192
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET forms... I tried painting, but the paintaing area provided by the form is only the client area - no visible way to paint on the title bar.
4
2380
by: Tonya | last post by:
Hi, Does anyone know how i can add controls to a progress bar. I have searched the internet but could not find any examples. what i want to add is a progress bar and a button. thx
5
1637
by: Patrick | last post by:
Hello I have the following problem. I have an aspx Page. This page contains an ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit the event of that button trough the WYSIWYG editor, so I co to the CodeBehind and add the Event in the InitializeComponent() Method like this this.lbTest.Click += new System.EventHandler(this.lbTest_Click); so far, all works fine. now if i go to the WYSIWYG editor, add another...
11
1584
by: Neo Geshel | last post by:
Greetings. Hopefully someone will be able to untie this Gordian Knot I have found myself bound up in. I am trying to add a submit button dynamically to a PlaceHolder. This button will help update a particular entry in a database. The button is added as thus: Sub LoadIntro() ...additional content that is dynamically loaded as well: a preview
5
1548
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That is, a user goes to the web page, which draws the current content out of the db and inserts into a "preview" area as well as the form itself. User makes changes, hits submit button. The page *should* refresh, with the changes saved to the db, and...
9
1179
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub respond to that button’s Click event. My main page has only one line:
0
8827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9208
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6654
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3182
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2559
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.