GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-May-2008, 19:02
mjcs100 mjcs100 is offline
Awaiting Email Confirmation
 
Join Date: May 2008
Posts: 4
mjcs100 is on a distinguished road

Help with a webpage


Hi everyone,

I made a web page 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:

HTML Code:
<!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:

C-SHARP / C# Code:
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();
}
}
Last edited by admin : 21-May-2008 at 04:47. Reason: Please insert your example C# codes between [CSHARP] and [/CSHARP] tags
  #2  
Old 13-Jun-2008, 12:30
JustinFox JustinFox is offline
Junior Member
 
Join Date: Mar 2008
Posts: 59
JustinFox will become famous soon enough

Re: Help with a webpage


If i were you I would try the page with out the <a></a> tags inside the asp:linkbutton.

because if you still have the submitform() function working, it will automatically submit the form first when you click on that asp:linkbutton.

everything else seems ok, I've never heard of clicking on a link and it showing the code behind file, unless you have a compile error.

Justin Fox
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make SOUND on server from webpage? insaneoctane Apache Web Server Forum 1 30-Oct-2007 13:12
How to read the contents of a webpage and write it to a file? asenthil MS Visual C++ / MFC Forum 3 23-Jan-2007 22:04
Processing a dynamic webpage VB 6.0 dogangoko Miscellaneous Programming Forum 0 25-Jul-2006 07:08
Problem with executing PHP in webpage fdgloworm Apache Web Server Forum 0 13-Feb-2006 12:43
Timing a webpage bkinnamon Apache Web Server Forum 6 14-Jun-2004 11:21

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:31.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.