473,804 Members | 3,019 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 1598
"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
1032
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
2790
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
9705
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...
1
10308
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
9134
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
7609
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
6846
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
5513
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
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
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
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.