473,721 Members | 2,111 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 1584
"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
1028
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
2781
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
8851
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
8736
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
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9138
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
9074
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
5992
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
4491
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
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2584
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.