![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2008
Posts: 1
Rep Power: 0
![]() |
Need help with website
Hi everyone,
I made a webpage in html that has a form, and instead of a button, I wanted a link. When the person clicks the link its supposed to call the code behind and do the click events I created for the link, but instead its trying to veiw the codebehind. The codebehind was done in C#. The link's href is linked with a javascript function to submit the form. The link part I think is working because its getting the submit request from the javascript so I think it's in my codebehind. I have done other pages just about like this one but they had buttons and I don't want buttons for this one. Could someone tell me what I did wrong. Any help would be appreciated. Here is the code. html with javascript: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" runat="server" type="text/JavaScript"> <!-- <!-- function submitform() { //v3.0 document.submitform.submit(); } //--> </script> </head> <body> <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="25" width="25" align="center"><form action="DLCounter/Downloads.aspx" name="submitform" method="post" runat="server"> <asp:linkbutton ID="lnkPLS" runat="server" Text="PLS"><a href="javascript: submitform()">Preschool's Learning Suite (PLS)</a></asp:linkbutton><br> <asp:linkbutton ID="lnkLYA" runat="server" Text="LYA"><a href="javascript: submitform()">Learning Your Alphabet</a></asp:linkbutton><br> <asp:linkbutton ID="lnkLYC" runat="server" Text="LYC"><a href="javascript: submitform()">Learning Your Colors</a></asp:linkbutton><br> <asp:linkbutton ID="lnkLYN" runat="server" Text="LYN"><a href="javascript: submitform()">Learning Your Numbers</a></asp:linkbutton> </form></td> </tr> </table> </body> </html> CodeBehind: using System; using System.Data; using System.Configuration; using System.Collections; using System.Net; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; namespace DownloadCounter { public partial class _Default : System.Web.UI.Page { SqlConnection dbConn = new SqlConnection(); SqlCommand dbCommand = new SqlCommand(); SqlDataReader dbReader; string answerClicked; int dlID; LinkButton lnkPLS = new LinkButton(); LinkButton lnkLYA = new LinkButton(); LinkButton lnkLYC = new LinkButton(); LinkButton lnkLYN = new LinkButton(); protected void Page_Load(object sender, EventArgs e) { lnkPLS.Attributes.Add("onclick", "return confirm('Download PLS?');"); lnkLYA.Attributes.Add("onclick", "return confirm('Download LYA?');"); lnkLYC.Attributes.Add("onclick", "return confirm('Download LYC?');"); lnkLYN.Attributes.Add("onclick", "return confirm('Download LYN?');"); if (IsPostBack) { lnkPLS.Click += new EventHandler(lnkPLS_Click); lnkLYA.Click += new EventHandler(lnkLYA_Click); lnkLYC.Click += new EventHandler(lnkLYC_Click); lnkLYN.Click += new EventHandler(lnkLYN_Click); } } protected void lnkPLS_Click(object sender, EventArgs e) { answerClicked = "PLS"; UpdateDataBase(lnkPLS); Response.Redirect("http://www.pc-boutique.net/programs/PLS_Win2000_XP.exe"); lnkPLS.Dispose(); } protected void lnkLYA_Click(object sender, EventArgs e) { answerClicked = "LYA"; UpdateDataBase(lnkLYA); Response.Redirect("http://www.pc-boutique.net/programs/LYA_Win2000_XP.exe"); lnkLYA.Dispose(); } protected void lnkLYC_Click(object sender, EventArgs e) { answerClicked = "LYC"; UpdateDataBase(lnkLYC); Response.Redirect("http://www.pc-boutique.net/programs/LYC_Win2000_XP.exe"); lnkLYC.Dispose(); } protected void lnkLYN_Click(object sender, EventArgs e) { answerClicked = "LYN"; UpdateDataBase(lnkLYN); Response.Redirect("http://www.pc-boutique.net/programs/LYN_Win2000_XP.exe"); lnkLYN.Dispose(); } private void UpdateDataBase(object sender) { try { dbConn.ConnectionString = "Data Source = sqlserver5.loosefoot.com; Initial Catalog = databasename; User Id = name; Password = password;"; dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "SELECT * FROM counter WHERE ProgID='" + answerClicked + "'"; dbReader = dbCommand.ExecuteReader(); if (dbReader.Read()) { if (answerClicked == dbReader["ProgID"].ToString()) { dlID = Convert.ToInt32(dbReader["Downloads"]); dlID++; dbConn.Close(); try { dbConn.ConnectionString = "Data Source = sqlserver5.loosefoot.com; Initial Catalog = databasename; User Id = name; Password = password;"; dbConn.Open(); dbCommand.Connection = dbConn; dbCommand.CommandText = "UPDATE counter SET Downloads= '" + dlID + "' WHERE ProgID = '" + answerClicked + " '"; 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(); } } |
|
|
|
|
|
#2 |
|
Man Bear Pig Hunter
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4
![]() |
Re: Need help with website
Use Visual Studio, look at the page in [Visual] and double click on the link. It will take you to the codebehind area and generate any code needed for it to work.
__________________
People who click "images" that end with .exe shouldn't have computers. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Website Contract Pricing | King | Coder's Corner Lounge | 4 | Mar 23rd, 2008 12:51 AM |
| www.thefilegarage.com - the world's ultimate file sharing website! | hervens48 | Show Off Your Open Source Projects | 15 | Feb 13th, 2008 9:12 PM |
| Website Making with html | hervens48 | HTML / XHTML / CSS | 5 | Jun 13th, 2006 6:55 PM |
| Anyone Good At Getting Software To Comunicate With Website | youngnoviceinneedofhelp | Other Programming Languages | 5 | Mar 13th, 2006 11:19 AM |