473,903 Members | 4,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding button programatically - NON-FUNCTIONAL!!

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
of the DB contents followed by a form that is pre-filled from the DB...
Dim submit as Button = New Button()
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

And the event handler is set up like this:

Sub UpdateIntro(sen der As Object, e As EventArgs)
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
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
The problem is that this doesn't work!!! The UpdateIntro sub simply
doesn't get fired!!

I'm pulling my hair out here, as I have also removed the AddHandler to
try this:

Private Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)
Handles submit.Click

But it also throws an error! I know that adding
submit.onClick= "UpdateIntr o" will also throw an error, but I simply
don't know what else to do or try!

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 8 '06 #1
11 1613
"Neo Geshel" <go****@geshel. org> wrote in message
news:IuzPf.1228 99$sa3.82272@pd 7tw1no...
but I simply don't know what else to do or try!


Save yourself a whole load of heartache and don't even try to add the button
dynamically - just set its Visible property to true or false as required...
Mar 8 '06 #2
Mark Rae wrote:
"Neo Geshel" <go****@geshel. org> wrote in message
news:IuzPf.1228 99$sa3.82272@pd 7tw1no...
but I simply don't know what else to do or try!


Save yourself a whole load of heartache and don't even try to add the button
dynamically - just set its Visible property to true or false as required...


Not so easy. You see, I am trying to make an admin interface more
efficient and flexible by programatically adding content as required. If
I can solve this one single problem, I can conceivably reduce the file
size (or, in other words, the amount of code) of the admin interface by
as much as 30%.

...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 8 '06 #3
I tried this out, and it works OK

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
LoadIntro()
End Sub
Sub LoadIntro()

Dim submit As Button = New Button
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)

Response.Write( "FIRED")

End Sub
"Neo Geshel" <go****@geshel. org> wrote in message
news:IuzPf.1228 99$sa3.82272@pd 7tw1no...
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
of the DB contents followed by a form that is pre-filled from the DB...
Dim submit as Button = New Button()
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

And the event handler is set up like this:

Sub UpdateIntro(sen der As Object, e As EventArgs)
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
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
The problem is that this doesn't work!!! The UpdateIntro sub simply
doesn't get fired!!

I'm pulling my hair out here, as I have also removed the AddHandler to
try this:

Private Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)
Handles submit.Click

But it also throws an error! I know that adding
submit.onClick= "UpdateIntr o" will also throw an error, but I simply
don't know what else to do or try!

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 8 '06 #4
Are you trying to click the button on the first page load or after a
postback? You have to re-create all dynamically added controls on every
postback.

Eliyahu

"Neo Geshel" <go****@geshel. org> wrote in message
news:IuzPf.1228 99$sa3.82272@pd 7tw1no...
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
of the DB contents followed by a form that is pre-filled from the DB...
Dim submit as Button = New Button()
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

And the event handler is set up like this:

Sub UpdateIntro(sen der As Object, e As EventArgs)
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
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
The problem is that this doesn't work!!! The UpdateIntro sub simply
doesn't get fired!!

I'm pulling my hair out here, as I have also removed the AddHandler to
try this:

Private Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)
Handles submit.Click

But it also throws an error! I know that adding
submit.onClick= "UpdateIntr o" will also throw an error, but I simply
don't know what else to do or try!

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 8 '06 #5
"Neo Geshel" <go****@geshel. org> wrote in message
news:l%zPf.1249 74$B94.55874@pd 7tw3no...
Not so easy. You see, I am trying to make an admin interface more efficient
and flexible by programatically adding content as required. If I can solve
this one single problem, I can conceivably reduce the file size (or, in
other words, the amount of code) of the admin interface by as much as 30%.


Hmm - I'd rethink your app design, if I were you...
Mar 8 '06 #6
One thing you need to watch out for is complexity being built IN because you
wanted to make the interface more efficient. I find this to be a major issue
if you have too many controls to deal with. The whole thing gets to complex
to manage.

Split your functionality into logical managable units and design your UI
acordingly. Remember, the user does not know intimately how your system
works, this can lead to assumptions of ease of use by the designer which
ultimately result in user confusion.
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
"Neo Geshel" <go****@geshel. org> wrote in message
news:l%zPf.1249 74$B94.55874@pd 7tw3no...
Not so easy. You see, I am trying to make an admin interface more
efficient and flexible by programatically adding content as required. If I
can solve this one single problem, I can conceivably reduce the file size
(or, in other words, the amount of code) of the admin interface by as much
as 30%.


Hmm - I'd rethink your app design, if I were you...

Mar 8 '06 #7
Dynamically loading controls can be quite a challenge. All the
controls that were added to the page dynamically most be loaded again
in the Init() event (either overriding OnInit or adding a handler to
Page.Init). The controls must be added by the Init event to the
IPostBackDataHa ndler and IPostBackEventH andler can work properly.
These are setup between the Init and Load event, and if the control
isn't there then it "misses the boat". The page remembers which events
need to fired during this process and then fires them after the Load
event.

If you have a series of controls you want to show/hide, group them
together into user controls (ascx files). Then, when you add them
dynamically, register a hidden field with the name of the skin file (or
files) you added. This information will be available to you when you
postback, and you can look at the values in the Init event and load the
appropriate user control in time for the page events to fire correctly.

Mar 8 '06 #8
Newbie wrote:
I tried this out, and it works OK

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
LoadIntro()
End Sub
Sub LoadIntro()

Dim submit As Button = New Button
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)

Response.Write( "FIRED")

End Sub


When I tried your method, I got the contents of LoadIntro() appearing
twice on the web page. When I clicked submit, I get a blank page.

What gives?

....Geshel
Mar 9 '06 #9
Neo Geshel wrote:
Newbie wrote:
I tried this out, and it works OK

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
LoadIntro()
End Sub
Sub LoadIntro()

Dim submit As Button = New Button
AddHandler submit.Click, AddressOf UpdateIntro
submit.id = "submit"
submit.Text = "Update Intro"
content.Control s.Add(submit)
End Sub

Sub UpdateIntro(ByV al sender As Object, ByVal e As EventArgs)

Response.Write( "FIRED")

End Sub


When I tried your method, I got the contents of LoadIntro() appearing
twice on the web page. When I clicked submit, I get a blank page.

What gives?

...Geshel


And when I replace your "private sub" with a normal one, LoadIntro()
appears only once on the page. But submitting the form still doesn't
update the DB, and gives me a blank page in response.

Stranger and stranger!

...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 9 '06 #10

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

Similar topics

8
1034
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
9
2802
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
10006
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
9853
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10882
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...
1
10990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10504
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...
0
9692
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8057
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
6100
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4316
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.