
mjcs100
Members-
Posts
7 -
Joined
-
Last visited
mjcs100's Achievements
Newbie (1/14)
0
Reputation
-
Hi I was wandering if someone could help me with a problem I'm having with my code behind for my submit buttons. What I did was create an html form in Dreamweaver and I created the code behind in Visual Studio 2005 to work with it. I have created a couple of applications in the past like this to work with a couple of other webpages I have but without the submit buttons being used this way and they work fine. Now I have 3 different html pages with the same thing, 2 forms and a submit button with the text "Download" for each one but has a different "ID". All the buttons are calling the same code behind. In the code behind, I want to have it distinguish which button was clicked by the "ID". I created a dummy in Visual Studio on the .aspx page with the buttons and it works but when I use the html page for it, and delete the info on the .aspx page, it won't post back to the html. I tried a couple of different ways to get the page_load event to recognize the html form, but been having no luck. Here is one of the codes I am trying to use, and I was wandering if someone could help me figure out what I am doing wrong. The html page's button's names and the buttons in visual studio are the exact same. protected void Page_Load(object sender, EventArgs e) { btn1.Click += new System.EventHandler(this.Download); btn2.Click += new System.EventHandler(this.Download); btn3.Click += new System.EventHandler(this.Download); btn4.Click += new System.EventHandler(this.Download); btn5.Click += new System.EventHandler(this.Download); btn6.Click += new System.EventHandler(this.Download); btn7.Click += new System.EventHandler(this.Download); btn8.Click += new System.EventHandler(this.Download); } protected void Download(object sender, System.EventArgs e) { switch (((Button)sender).OnClientClick) { case "btn1": //code for btn1. //code to updateDataBase break; case "btn2": //code for btn2. //code to updateDataBase break; case "btn3": //code for btn3 //code to updateDataBase break; case "btn4": //code for btn4 //code to updateDataBase break; case "btn5": //code for btn5 //code to updateDataBase break; case "btn6": //code for btn6 //code to updateDataBase break; case "btn7": //code for btn7 //code to updateDataBase break; case "btn8": //code for btn8 //code to updateDataBase break; } lblStatus.Text = dlID.ToString(); } private void UpdateDataBase(object sender) { try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "SELECT * FROM table WHERE column='" + btnClicked + "'"; dbReader = dbCommand.ExecuteReader(); if (dbReader.Read()) { if (btnClicked == dbReader["column"].ToString()) { dlID = Convert.ToInt32(dbReader["column"]); dlID++; dbConn.Close(); try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "UPDATE table SET acolumn= '" + dlID + "' WHERE acolumn = '" + btnClicked + " '"; dbReader = dbCommand.ExecuteReader(); lblStatus.Text = dlID.ToString(); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } finally { dbConn.Close(); } } ____________________________________________________________ This is the second way I tried it and no luck with this one. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } else { lblStatus.Text = dlID.ToString(); } } protected void btn1_Click(object sender, EventArgs e) { code for btn1 } protected void btn2_Click(object sender, EventArgs e) { code for btn2 } protected void btn3_Click(object sender, EventArgs e) { code for btn3 } protected void btn4_Click(object sender, EventArgs e) { code for btn4 } protected void btn5_Click(object sender, EventArgs e) { code for btn5 } protected void btn6_Click(object sender, EventArgs e) { code for btn6 } protected void btn7_Click(object sender, EventArgs e) { code for btn7 } protected void btn8_Click(object sender, EventArgs e) { code for btn8 } private void UpdateDataBase(object sender) { try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "SELECT * FROM table WHERE column='" + btnClicked + "'"; dbReader = dbCommand.ExecuteReader(); if (dbReader.Read()) { if (btnClicked == dbReader["column"].ToString()) { dlID = Convert.ToInt32(dbReader["column"]); dlID++; dbConn.Close(); try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "UPDATE table SET acolumn= '" + dlID + "' WHERE acolumn = '" + btnClicked + " '"; dbReader = dbCommand.ExecuteReader(); lblStatus.Text = dlID.ToString(); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } finally { dbConn.Close(); } } ______________________________________________________ This is my last way I have tried, but it keeps telling me "The event 'System.Web.UI.WebControls.Button.Click' can only appear on the left hand side of += or -=". protected void Page_Load(object sender, EventArgs e) { if (btn1.Click = true) { code for btn1 } else if (btn2.Click = true) { code for btn2 } else if (btn3.Click = true) { code for btn3 } else if (btn4.Click = true) { code for btn4 } else if (btn5.Click = true) { code for btn5 } else if (btn6.Click = true) { code for btn6 } else if (btn7.Click = true) { code for btn7 } else if (btn8.Click = true) { code for btn8 } } private void UpdateDataBase(object sender) { try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "SELECT * FROM table WHERE column='" + btnClicked + "'"; dbReader = dbCommand.ExecuteReader(); if (dbReader.Read()) { if (btnClicked == dbReader["column"].ToString()) { dlID = Convert.ToInt32(dbReader["column"]); dlID++; dbConn.Close(); try { dbConn.ConnectionString = //code to access mssql database dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "UPDATE table SET acolumn= '" + dlID + "' WHERE acolumn = '" + btnClicked + " '"; dbReader = dbCommand.ExecuteReader(); lblStatus.Text = dlID.ToString(); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } finally { dbConn.Close(); } } I hope someone will be able to help me. Thanks
-
Hi. I am making a program that I want to have 5 very short avi's to play as soon as the program is loaded. At the same time I have 5 images of the words that go with each video for people that can not hear the sounds from the video. I put them into an Array and try to have windows media player play the Array along with the image array so they come up at the same time as their video does. I then use the player.url to start the videos and it does go through each array, but when the videos load, the only one that loads is the last one or next to last one. Does any one know how to get the player to play all of the avi's in an array or even how to load the array other than player.url. If there is a tutorial or anything that someone knows of, please let me know where to go to. mjcs
-
Thanks PlausiblyDamp for replying. I checked the local pc under administrative tools/services and it says the Iis is running. I don't see anything about smtp though. I dont know anything hardly at all when it comes to things about admisistrative tools, but wouldnt the smtp be installed if i can send mail through the default email handler? That's what I originally was trying to do was to get the submit button to use the default mail handler of the person's pc that wanted to purchase the product. I just used the deliverynotificationoption to see if it went through ok, which I just removed. Yes I got an error when I tried to send it via smtp. I uploaded a jpeg of it to show you. Is there something I'm missing in the code above that directs the info to be sent from someones computer using their default mail client? Thanks
-
Hi. I was wandering if you could look at my code i have for a submit button on a purchase order form. In the program when a customer wants to purchase the product, I want the info from the form to be emailed to me from the form. I checked out different sites with different answers but nothing works. I had to pick the delivery method as "PickupDirectoryFromIis" b/c it wouldnt let me specify a default mail client. I stepped through the code and it said it was successfully sent but it never comes in my default emailclient. Here is the code for a submit button. Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click Dim email As New MailMessage Dim messageBody As String = "LblProdName.Text" & "lblProdCode.Text" & "txtFName.Text" & "txtLName.Text" & "txtAdd1.Text" & "txtAdd2.Text" & "txtCity.Text" & "txtZipCode.Text" & "txtPhone.Text" & "txtEmailAddress.Text" Dim smtp As New SmtpClient Try email.From = New MailAddress("user@localhost") email.To.Add("me@mydomain.net") email.Subject = "Submitted Information" email.Body = messageBody.ToString smtp.Host = ("mail.domain.net") smtp.Port = 25 smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis smtp.Send(email) If DeliveryNotificationOptions.OnSuccess = DeliveryNotificationOptions.OnSuccess Then MessageBox.Show("Information Was Successfully Submitted") ElseIf DeliveryNotificationOptions.OnFailure = DeliveryNotificationOptions.OnFailure Then MessageBox.Show("Information Was Not Submitted") End If Catch ex As Exception MessageBox.Show(ex.ToString()) email = Nothing End Try txtFName.Text = "" txtLName.Text = "" txtAdd1.Text = "" txtAdd2.Text = "" txtCity.Text = "" txtZipCode.Text = "" txtPhone.Text = "" txtEmailAddress.Text = "" cboState.Text = "Please Select" cboCountry.Text = "Please Select" cboVisa.Checked = False cboMasterCard.Checked = False cboDiscover.Checked = False cboAmExp.Checked = False rdoShareIt.Checked = False rdoPayPal.Checked = False Me.Close() End Sub
-
Thanks Thanks for your answers. I got it figured out from a local friend that it was an error from my crystal reports that I didnt have installed with the program. It now works...:)
-
clean machine Hi Cags, yes it was packaged with the program and installed first b/f the program but still the error comes up. I hope this helps. mjcs
-
Hi. I hope this is the right place for this as I am new to this site and new to VS.net. I was wandering if anyone could tell me what it means when an error says "Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated." I am making a program in Visual Basic using Visual Studio.Net and I have a timer in it. The form is displayed with the options to select and give the right/wrong answer and then the form is supposed to reload itself with different questions and answers. It seems to work fine, but the error will not go away and when i go to deploy the project, it gives me errors which I think are do to the previous ones. The line that gives the error says: Me.BeginnersTestFindLetter_Load(Me.btnImage1, e.Empty) with a green and red line under e.Empty. I have tried to put Me.ShowDialog, but it tells me that the form is already visible. I have a snapshot of the error if that is helpful, I can post it. I hope someone will be able to tell me how to fix it. Thank you. mjcs Edit: I figured out what the problem was with the error, but when I still go to deploy (build) the program and run it on a clean machine that has no visual studio installed, it still has the problem I had b/f from deploying the project which I thought was from the error I just fixed. After I installed the program and launch it, it comes up that it has encountered a problem and needs to shut down. When I look at what the error report contains, it says system: InvalidOperationException. It keeps coming back each time I deploy (build) the program and install it on the clean machine. Does anyone know how to resolve this issue.