|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding button programatically - NON-FUNCTIONAL!!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.Controls.Add(submit) End Sub And the event handler is set up like this: Sub UpdateIntro(sender As Object, e As EventArgs) Dim myConn as New OleDbConnection(ConfigurationSettings.AppSettings("strConn")) Dim myCmd as New OleDbCommand("UPDATE tblIntro SET [Comment]=@Comment", myConn) myConn.Open() myCmd.CommandType = CommandType.Text myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value = RepChar(Request.Form("IntroComment")) myCmd.ExecuteNonQuery() 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(ByVal sender As Object, ByVal e As EventArgs) Handles submit.Click But it also throws an error! I know that adding submit.onClick="UpdateIntro" 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. *********************************************************************** "Neo Geshel" <got***@geshel.org> wrote in message news:IuzPf.122899$sa3.82272@pd7tw1no...>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... Mark Rae wrote:
> "Neo Geshel" <got***@geshel.org> wrote in message Not so easy. You see, I am trying to make an admin interface more > news:IuzPf.122899$sa3.82272@pd7tw1no... > >> 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... > 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. *********************************************************************** I tried this out, and it works OK
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.Controls.Add(submit) End Sub Sub UpdateIntro(ByVal sender As Object, ByVal e As EventArgs) Response.Write("FIRED") End Sub "Neo Geshel" <got***@geshel.org> wrote in message news:IuzPf.122899$sa3.82272@pd7tw1no...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.Controls.Add(submit) End Sub And the event handler is set up like this: Sub UpdateIntro(sender As Object, e As EventArgs) Dim myConn as New OleDbConnection(ConfigurationSettings.AppSettings("strConn")) Dim myCmd as New OleDbCommand("UPDATE tblIntro SET [Comment]=@Comment", myConn) myConn.Open() myCmd.CommandType = CommandType.Text myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value = RepChar(Request.Form("IntroComment")) myCmd.ExecuteNonQuery() 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(ByVal sender As Object, ByVal e As EventArgs) Handles submit.Click But it also throws an error! I know that adding submit.onClick="UpdateIntro" 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. *********************************************************************** Newbie wrote:
Show quoteHide quote > I tried this out, and it works OK When I tried your method, I got the contents of LoadIntro() appearing > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) 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.Controls.Add(submit) > End Sub > > Sub UpdateIntro(ByVal sender As Object, ByVal e As EventArgs) > > Response.Write("FIRED") > > End Sub twice on the web page. When I clicked submit, I get a blank page. What gives? ....Geshel Neo Geshel wrote:
Show quoteHide quote > Newbie wrote: And when I replace your "private sub" with a normal one, LoadIntro() >> I tried this out, and it works OK >> >> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As >> System.EventArgs) 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.Controls.Add(submit) >> End Sub >> >> Sub UpdateIntro(ByVal 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 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. *********************************************************************** 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" <got***@geshel.org> wrote in message news:IuzPf.122899$sa3.82272@pd7tw1no...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.Controls.Add(submit) End Sub And the event handler is set up like this: Sub UpdateIntro(sender As Object, e As EventArgs) Dim myConn as New OleDbConnection(ConfigurationSettings.AppSettings("strConn")) Dim myCmd as New OleDbCommand("UPDATE tblIntro SET [Comment]=@Comment", myConn) myConn.Open() myCmd.CommandType = CommandType.Text myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value = RepChar(Request.Form("IntroComment")) myCmd.ExecuteNonQuery() 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(ByVal sender As Object, ByVal e As EventArgs) Handles submit.Click But it also throws an error! I know that adding submit.onClick="UpdateIntro" 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. *********************************************************************** Eliyahu Goldin wrote:
> Are you trying to click the button on the first page load or after a The button is meant to be clicked on the first page load (technically). > postback? You have to re-create all dynamically added controls on every > postback. > > Eliyahu > Any button clicks should fire the UpdateIntro(), at the end of which the LoadIntro() is called, sending the user the original form again, but this time populated with updated material. ...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. *********************************************************************** Sorry to hear my approach didn't work well for you. If controls are
being loaded twice, then that means you're calling the function twice- could this be possible? THis can happen when you add a control in the Init event, then add the control again after the page is loaded. Does it occur when the page is first loaded, or only after a postback? Secondly, as for the page not showing up, it sounds like the postback isn't being handled correctly. THis can be related to your first problem. I wrote some code that adds a button to the page dynamically, stores a value as a hidden field, then loads the button in the init event. You'll need to wire up the Page_Init event yourself via Page.Init += new EventHandler(Page_Init); ANyway, you should be able to get it to work and expand on the basic idea. You can replace the button with a more complex usercontrol, or store a series of controls in the hidden field if you want to add more than one: private Button btn; protected void Page_Init(object sender, EventArgs e) { string controlName; controlName = Request.Form["ControlToAdd"]; if (controlName == "btn") { btn = new Button(); btn.ID = "btn"; btn.Click += new EventHandler(btn_Click); this.form1.Controls.Add(btn); } } void btn_Click(object sender, EventArgs e) { string s; s = "The button has been clicked"; } protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { btn = new Button(); btn.ID = "btn"; this.form1.Controls.Add(btn); //no need to wire up an event handler here. this.RegisterHiddenField("ControlToAdd", "btn"); } } Good luck!
Checking for new versions in a setup project
ADO With SQL Transactions Progressbar and treeview stops refreshing converting from combobox.text to long() Preventing Explorer Window from Displaying when Pen Drive Inserted Error on Graphics CompositingMode.SourceCopy Numeric Variables sending email when running on diff machine Can anyone convert this to VB? Getting Extended File Properties |
|||||||||||||||||||||||