|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding Button Programmatically REDUX - STILL NONFUNCTIONALI 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 the new content in the preview area and in the form. What happens is that the entire "content" section of the page vanishes. Everything. Boom. Poof. Bye-bye. It's as if the sub that catches the button action simply doesn't fire. And when I refresh the page, the original content - not the changed content - comes back up, *proving* that the database insert of the changed content FAILED TO FIRE. Below is the code-behind that I am using: Imports System 'Imports System.Configuration Imports System.Data Imports System.Data.OleDb 'Imports System.Drawing 'Imports System.Drawing.Imaging 'Imports System.IO 'Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.HTMLControls Public Class TeamMetz Inherits Page Dim vbCrLf As String = Microsoft.VisualBasic.vbCrLf Dim strYear As String = DateTime.Now.Year.ToString() Dim strWarning As String = vbCrLf & " <p>Have you <a href=""/rules.aspx"">read 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(System.Configuration.ConfigurationSettings.AppSettings("strConn")) Protected Sub Page_Load(sender As Object, e As EventArgs) Dim strURL as String = Request.RawURL.ToString() Dim strDO as String = Request.QueryString("do") Dim intID as Integer = Request.QueryString("id") Dim strP as String = Request.QueryString("parent") Dim strC as String = Request.QueryString("child") Dim strG as String = Request.QueryString("gchild") Dim intE as Integer = Request.QueryString("entry") Controls.Add(New LiteralControl(" ... ")) 'sets up the opening HTML, the meta tags and the page header. If Not IsPostBack Then Select Case strDo Case "add" Case "edit" Case "delete" Case "intro" LoadIntro() Case Else Controls.Add(New 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(New LiteralControl(" ... ")) 'sets up the page footer and the closing HTML End Sub Sub LoadIntro() Controls.Add(New LiteralControl(" <h2>Edit Intro</h2>" & strWarning)) myForm.ID = "myForm" Controls.Add(myForm) Dim myCmd as New OleDbCommand("SELECT [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(myCmd.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 = "IntroComment" textarea.Text = myCmd.ExecuteScalar() textarea.Rows = "8" textarea.Columns = "80" textarea.TextMode = TextBoxMode.MultiLine 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 Sub UpdateIntro(sender As Object, e As System.EventArgs) 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 Function FormatDate(sItem as Object) as String Return String.Format("<p class=""small"">Posted: <i>{0:dddd, dd MMMMM, yyyy}</i></p>", sItem) End Function Function FormatData(sItem) as String FormatData=sItem.Replace(vbcrlf,"</p>" & vbCrLf & " <p>").Replace("[b]","<b>").Replace("[/b]","</b>").Replace("[i]","<i>").Replace("[/i]","</i>").Replace("</p>" Function RepChar(sItem) as String& vbCrLf & " <p>[list]</p>" & vbCrLf & " <p>[item]","</p>" & vbCrLf & " <ul>" & vbCrLf & " <li>").Replace("</p>" & vbCrLf & " <p>[item]","</li>" & vbCrLf & " <li>").Replace("</p>" & vbCrLf & " <p>[/list]","</li>" & vbCrLf & " </ul>" & vbCrLf) End Function RepChar=sItem.Replace("'","’").Replace(" & ", " & ").Replace("<","<").Replace(">",">") End ClassEnd Function As you can see, the *logical* progression of events is that the page is loaded, the user clicks on "edit intro", the edit intro page comes up (complete with preview area and pre-filled form). The user then makes changes, and the button gets clicked. The button *should* call UpdateIntro(), but it clearly does not, since the DB never gets updated. WHY? WHY? WHY? Why does the DB not update??? The LoadIntro() clearly has the button referencing the UpdateIntro() sub, but that sub fails to fire when the page gets submitted. It's like that sub is completely ignored. WHY? 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. *********************************************************************** Are you trying to insert a form within a form in ASP.NET? If so, it will
crash. "Neo Geshel" <got***@geshel.org> wrote in message news:HE1Rf.137411$H%4.1494@pd7tw2no...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 the new content in the preview area and in the form. What happens is that the entire "content" section of the page vanishes. Everything. Boom. Poof. Bye-bye. It's as if the sub that catches the button action simply doesn't fire. And when I refresh the page, the original content - not the changed content - comes back up, *proving* that the database insert of the changed content FAILED TO FIRE. Below is the code-behind that I am using: Imports System 'Imports System.Configuration Imports System.Data Imports System.Data.OleDb 'Imports System.Drawing 'Imports System.Drawing.Imaging 'Imports System.IO 'Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.HTMLControls Public Class TeamMetz Inherits Page Dim vbCrLf As String = Microsoft.VisualBasic.vbCrLf Dim strYear As String = DateTime.Now.Year.ToString() Dim strWarning As String = vbCrLf & " <p>Have you <a href=""/rules.aspx"">read 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(System.Configuration.ConfigurationSettings.AppSettings("strConn")) Protected Sub Page_Load(sender As Object, e As EventArgs) Dim strURL as String = Request.RawURL.ToString() Dim strDO as String = Request.QueryString("do") Dim intID as Integer = Request.QueryString("id") Dim strP as String = Request.QueryString("parent") Dim strC as String = Request.QueryString("child") Dim strG as String = Request.QueryString("gchild") Dim intE as Integer = Request.QueryString("entry") Controls.Add(New LiteralControl(" ... ")) 'sets up the opening HTML, the meta tags and the page header. If Not IsPostBack Then Select Case strDo Case "add" Case "edit" Case "delete" Case "intro" LoadIntro() Case Else Controls.Add(New 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 thedatabase</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(New LiteralControl(" ... ")) 'sets up the page footer and the closing HTML End Sub Sub LoadIntro() Controls.Add(New LiteralControl(" <h2>Edit Intro</h2>" & strWarning)) myForm.ID = "myForm" Controls.Add(myForm) Dim myCmd as New OleDbCommand("SELECT [Comment] FROM [tblIntro]", myConn) myConn.Open() myForm.Controls.Add(New LiteralControl(" <p>This is what is currently in the Database:</p>" & vbCrLf & " <blockquote>" & vbCrLf & " of the database and submit the changes:</p>" & vbCrLf & " <div<p>" & FormatData(myCmd.ExecuteScalar()) & "</p>" & vbCrLf & " </blockquote>" & vbCrLf & " <p>Use the form below to edit the contents class=""center"">" & vbCrLf & " ")) Dim textarea As New TextBox textarea.id = "IntroComment" textarea.Text = myCmd.ExecuteScalar() textarea.Rows = "8" textarea.Columns = "80" textarea.TextMode = TextBoxMode.MultiLine 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 Sub UpdateIntro(sender As Object, e As System.EventArgs) 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 Function FormatDate(sItem as Object) as String Return String.Format("<p class=""small"">Posted: <i>{0:dddd, dd MMMMM, yyyy}</i></p>", sItem) End Function Function FormatData(sItem) as String FormatData=sItem.Replace(vbcrlf,"</p>" & vbCrLf & " <p>").Replace("[b]","<b>").Replace("[/b]","</b>").Replace("[i]","<i>").Replace("[/i]","</i>").Replace("</p>" Function RepChar(sItem) as String& vbCrLf & " <p>[list]</p>" & vbCrLf & " <p>[item]","</p>" & vbCrLf & " <ul>" & vbCrLf & " <li>").Replace("</p>" & vbCrLf & " <p>[item]","</li>" & vbCrLf & " <li>").Replace("</p>" & vbCrLf & " <p>[/list]","</li>" & vbCrLf & " </ul>" & vbCrLf) End Function RepChar=sItem.Replace("'","'").Replace(" & ", " & ").Replace("<","<").Replace(">",">") End ClassEnd Function As you can see, the *logical* progression of events is that the page is loaded, the user clicks on "edit intro", the edit intro page comes up (complete with preview area and pre-filled form). The user then makes changes, and the button gets clicked. The button *should* call UpdateIntro(), but it clearly does not, since the DB never gets updated. WHY? WHY? WHY? Why does the DB not update??? The LoadIntro() clearly has the button referencing the UpdateIntro() sub, but that sub fails to fire when the page gets submitted. It's like that sub is completely ignored. WHY? 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. *********************************************************************** Ken Cox - Microsoft MVP wrote:
> Are you trying to insert a form within a form in ASP.NET? If so, it will Ummm.... no. Didn't you read what I wrote?> crash. On the first viewing of the page (If Not IsPostBack Then), when do=intro, the sub LoadIntro() is called. This extracts data from the database, and puts it into a preview section, as well as directly into a form for editing. When the contents of the form are edited and submitted, the sub UpdateIntro() is *supposed* to fire. It is *supposed* to take the form contents, and submit them to the database, before calling the sub LoadIntro(). The problem is, the submit button of the form FAILS TO CALL THE UPDATEINTRO() SUB, and so THE DATABASE INSERT FAILS TO OCCUR, and the reloading of the preview/filled form also fails to occur. BTW, the only contents of my main page is the page attribute. I am dynamically loading all of the page contents (<html>, <title></title>, <page>, </page>, </html>, etc.) from the code-behind. I intend to compile the results once I get it working. 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 wrote:
Show quoteHide quote > Ken Cox - Microsoft MVP wrote: As an addendum, here is how the HTML ends up in the browser's source >> Are you trying to insert a form within a form in ASP.NET? If so, it >> will crash. > > Ummm.... no. Didn't you read what I wrote? > > On the first viewing of the page (If Not IsPostBack Then), when > do=intro, the sub LoadIntro() is called. This extracts data from the > database, and puts it into a preview section, as well as directly into a > form for editing. > > When the contents of the form are edited and submitted, the sub > UpdateIntro() is *supposed* to fire. It is *supposed* to take the form > contents, and submit them to the database, before calling the sub > LoadIntro(). > > The problem is, the submit button of the form FAILS TO CALL THE > UPDATEINTRO() SUB, and so THE DATABASE INSERT FAILS TO OCCUR, and the > reloading of the preview/filled form also fails to occur. > > BTW, the only contents of my main page is the page attribute. I am > dynamically loading all of the page contents (<html>, <title></title>, > <page>, </page>, </html>, etc.) from the code-behind. I intend to > compile the results once I get it working. > > TIA. > ...Geshel preview window: <h2>Edit Intro</h2> <p>Have you <a href="/rules.aspx">read the rules</a> for adding content? Do you know how to <a href="/formatting.aspx">properly format text</a>?</p> <form name="myForm" method="post" action="default.aspx?do=intro" id="myForm"> <input type="hidden" name="__VIEWSTATE" value="dDw1MzgxOzs+m5H4fRpTaPkfBKkPgV/0vEOzo+4=" /> <p>This is what is currently in the Database:</p> <blockquote> <p> ... Contents of Intro, with proper formatting ...</p> </blockquote> <p>Use the form below to edit the contents of the database and submit the changes:</p> <div class="center"> <textarea name="IntroComment" rows="8" cols="80" id="IntroComment"> ... Contents of Intro, withOUT proper formatting ... </textarea><br /> <input type="submit" name="submit" value="Update Intro" id="submit" /> </div> </form> This is what *should* be coming up *every time* for that page, even *after* clicking on the submit button. What I have noticed is that the textarea and the submit button don't have their usual viewstate-munged Id's. Their ID's are plain, as if viewstate was turned off. ...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. *********************************************************************** Well the error I got with your codes was
Exception Details: System.Web.HttpException: A page can have only one server-side Form tag. "Neo Geshel" <got***@geshel.org> wrote in message news:Ku2Rf.137463$H%4.111154@pd7tw2no...Ken Cox - Microsoft MVP wrote: > Are you trying to insert a form within a form in ASP.NET? If so, it will Ummm.... no. Didn't you read what I wrote?> crash. On the first viewing of the page (If Not IsPostBack Then), when do=intro, the sub LoadIntro() is called. This extracts data from the database, and puts it into a preview section, as well as directly into a form for editing. When the contents of the form are edited and submitted, the sub UpdateIntro() is *supposed* to fire. It is *supposed* to take the form contents, and submit them to the database, before calling the sub LoadIntro(). The problem is, the submit button of the form FAILS TO CALL THE UPDATEINTRO() SUB, and so THE DATABASE INSERT FAILS TO OCCUR, and the reloading of the preview/filled form also fails to occur. BTW, the only contents of my main page is the page attribute. I am dynamically loading all of the page contents (<html>, <title></title>, <page>, </page>, </html>, etc.) from the code-behind. I intend to compile the results once I get it working. 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. *********************************************************************** Ken Cox - Microsoft MVP wrote:
> Well the error I got with your codes was Well, there is only one instance of a FORM tag that was dynamically > > Exception Details: System.Web.HttpException: A page can have only one > server-side Form tag. created, as you can see from the code-behind. Where was your second FORM tag coming from?? Remember, the only thing on the ASPX page was the @page directive. Nothing else. ...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. *********************************************************************** |
|||||||||||||||||||||||