Adding codebehind files to an app. developed using .net framework

G

Guest

I made a site using a text editor and the .net framework..compiling it from
the command line. I now have visual studio 2003 and want to alter the
application from within it. Below is one such file, can someone give me an
idea on this?

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<script runat="server">

void Page_Load (object Sender, EventArgs e) {


}

void makeselection_Click(Object sender, System.EventArgs e) {
string col;
string cat;
string yea;
string reg;
string cou;
string app;

/*try
{
Session["color"] = color.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["color"] = "-1";

}
try
{
Session["category"] = category.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["category"] = "-1";
}
try
{
Session["year"] = year.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["year"] = "-1";
}

try
{
Session["region"] = region.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["region"] = "-1";
}
try
{
Session["country"] = country.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["country"] = "-1";
}

try
{
Session["appellation"] = appellation.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["appellation"] = "-1";
}

*/
col = color.SelectedItem.Text;
if (col!="") {
Session["color"] = color.SelectedItem.Text;
}
else {
Session["color"] = "";
}

cat = category.SelectedItem.Text;
if (cat!="") {
Session["category"] = category.SelectedItem.Text;
}
else {
Session["category"] = "";
}
yea = year.SelectedItem.Text;
if (yea!="") {
Session["year"] = year.SelectedItem.Text;
}
else {
Session["year"] = "";
}
reg = region.SelectedItem.Text;
if (reg!="") {
Session["region"] = region.SelectedItem.Text;
}
else {
Session["region"] = "";
}
cou = country.SelectedItem.Text;
if (cou!="") {
Session["country"] = region.SelectedItem.Text;
}
else {
Session["country"] = "";
}
app = appellation.SelectedItem.Text;
if (app!="") {
Session["appellation"] = appellation.SelectedItem.Text;

}
else {
Session["appellation"] = "";
}


//Session["color"] = color.SelectedItem.Text;
// Session["category"] = category.SelectedItem.Text;
//Session["price"] = price.SelectedIndex;
// Session["year"] = year.SelectedItem.Text;





Response.Redirect("winelist.aspx");



}
void emailoffer(Object sender, System.EventArgs e)
{



}
</script>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive">
<title>Untitled Page</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
..style2 {font-size: 9px}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<p align="center"><img src="e2.jpg" width="694" height="209"></p>
<table width="81%" height="203" border="0">
<tr height="206">
<td width="54%" height="206"> <div
align="center">Shop the largest online assortment of wines from around the
world.From exciting new wines to monthly best sellers, you'll find
greattasting wines for any occasion. </div></td>
<td width="46%" height="206"><img src="top1.gif" width="229"
height="170"></td>
</tr>
</table>
<table width="769" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="759"><hr noshade></td>
</tr>
</table>
<p> </p>
<form runat="server">
Category: <asp:DropDownList id="category" runat="server">
<asp:ListItem Text=""/>
<asp:ListItem Text="Arneis"/>
<asp:ListItem Text="Barbera"/>
<asp:ListItem Text="Bordeaux"/>
<asp:ListItem Text="Cabernet Sauvignon"/>

<asp:ListItem Text="Chardonnay"/>
<asp:ListItem Text="Coastal South Africa"/>

<asp:ListItem Text="Colchagua"/>
<asp:ListItem Text="Corvina"/>
<asp:ListItem Text="Fortified Blend"/>
<asp:ListItem Text="Fume Blanc"/>
<asp:ListItem Text="Gamay"/>
<asp:ListItem Text="Greco"/>
<asp:ListItem Text="Malbec"/>
<asp:ListItem Text="Marsanne"/>
<asp:ListItem Text="Merlot"/>
<asp:ListItem Text="Montepulciano"/>
<asp:ListItem Text="Moscato"/>
<asp:ListItem Text="Muscadet"/>
<asp:ListItem Text="Nebbiolo"/>
<asp:ListItem Text="Pauillac"/>
<asp:ListItem Text="Pinot Blanc"/>
<asp:ListItem Text="Pinot Bianco"/>
<asp:ListItem Text="Pinot Grigio"/>
<asp:ListItem Text="Pinot Gris"/>
<asp:ListItem Text="Pinot Noir"/>
<asp:ListItem Text="Primitivo "/>
<asp:ListItem Text="Red Blend"/>
<asp:ListItem Text="Rhone Valley"/>
<asp:ListItem Text="Riesling "/>
<asp:ListItem Text="Rose Blend "/>
<asp:ListItem Text="Sake"/>
<asp:ListItem Text="Sangiovese"/>
<asp:ListItem Text="Sauvignon Blanc"/>
<asp:ListItem Text="Semillon "/>
<asp:ListItem Text="Shiraz"/>
<asp:ListItem Text="Sparkling Blend "/>
<asp:ListItem Text="Sweet Blend"/>
<asp:ListItem Text="Syrah"/>
<asp:ListItem Text="Tempranillo"/>
<asp:ListItem Text="White"/>
<asp:ListItem Text="White Blend"/>
<asp:ListItem Text="Viognier"/>
<asp:ListItem Text="Zinfandel"/>
</asp:DropDownList>

Region:
<asp:DropDownList id="region" runat="server">
<asp:ListItem Text=""/>
<asp:ListItem Text="Abruzzi"/>
<asp:ListItem Text="Alsace"/>
<asp:ListItem Text="Andalucia"/>
<asp:ListItem Text="Bordeaux"/>
<asp:ListItem Text="Burgundy"/>
<asp:ListItem Text="California"/>
<asp:ListItem Text="Campania"/>
<asp:ListItem Text="Catalonia"/>
<asp:ListItem Text="Coastal South Africa"/>

<asp:ListItem Text="France"/>
<asp:ListItem Text="Friuli-Venezia Giulia"/>

<asp:ListItem Text="Languedoc-Roussillon"/>

<asp:ListItem Text="La Rioja"/>
<asp:ListItem Text="Loire Valley"/>
<asp:ListItem Text="Lombardy"/>
<asp:ListItem Text="Madeira"/>
<asp:ListItem Text="Maule Valle"/>
<asp:ListItem Text="Mendoza"/>
<asp:ListItem Text="New South Wales"/>

<asp:ListItem Text="Oregon"/>
<asp:ListItem Text="Paarl"/>
<asp:ListItem Text="Piedmont"/>
<asp:ListItem Text="Puglia"/>
<asp:ListItem Text="Rapel"/>
<asp:ListItem Text="Rhone Valley"/>
<asp:ListItem Text="Sake"/>
<asp:ListItem Text="Sicily"/>
<asp:ListItem Text="Southern"/>
<asp:ListItem Text="South Island, NZ"/>

<asp:ListItem Text="South Africa"/>
<asp:ListItem Text="South Australia "/>

<asp:ListItem Text="Trentino-Alto Adige"/>

<asp:ListItem Text="Tuscany"/>
<asp:ListItem Text="Veneto"/>
<asp:ListItem Text="Vin de Pays"/>
<asp:ListItem Text="Washington"/>
<asp:ListItem Text="Western Australia"/>

</asp:DropDownList>
Country:

<asp:DropDownList id=country runat=server>
<asp:ListItem Text=""/>
<asp:ListItem Text="Argentina"/>
<asp:ListItem Text="Australia"/>
<asp:ListItem Text="Chile"/>
<asp:ListItem Text="France"/>
<asp:ListItem Text="Italy"/>
<asp:ListItem Text="Japan"/>
<asp:ListItem Text="New Zealand"/>
<asp:ListItem Text="Spain"/>
<asp:ListItem Text="South Africa"/>
 
C

Cowboy \(Gregory A. Beamer\)

Create a new web project and import all of your ASPX files. You should be
asked if you would like to create code behind pages. Then, fix any compile
errors (from having Page_Load in two places, most likely).

Steps to "fix" your site, if necessary (use what you need)
1. Create file for CodeBehind (assume C# for all your examples)
2. Name same as ASPX with .cs
3. Add Page_Load and other pertinent events (also make sure class file is
named correctly)
4. Put in same folder as ASPX
5. See all in server explorer, include in project
6. Add CodeBehind="" and Inherits="" to the @ tag in the ASPX
7. Make sure you have no dupe events in your ASPX and the code behind

For step 6, add a page to the site and examine the @ tag. It is very easy to
figure out. It is just a bit tedious and time consuming.

In your case, everything in the <script> block should go in code behind
file.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think outside the box!
***********************************************
dinesh said:
I made a site using a text editor and the .net framework..compiling it from
the command line. I now have visual studio 2003 and want to alter the
application from within it. Below is one such file, can someone give me an
idea on this?

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<script runat="server">

void Page_Load (object Sender, EventArgs e) {


}

void makeselection_Click(Object sender, System.EventArgs e) {
string col;
string cat;
string yea;
string reg;
string cou;
string app;

/*try
{
Session["color"] = color.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["color"] = "-1";

}
try
{
Session["category"] = category.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["category"] = "-1";
}
try
{
Session["year"] = year.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["year"] = "-1";
}

try
{
Session["region"] = region.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["region"] = "-1";
}
try
{
Session["country"] = country.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["country"] = "-1";
}

try
{
Session["appellation"] = appellation.SelectedItem.Text;
}
catch(System.Exception NotSelected)
{
Session["appellation"] = "-1";
}

*/
col = color.SelectedItem.Text;
if (col!="") {
Session["color"] = color.SelectedItem.Text;
}
else {
Session["color"] = "";
}

cat = category.SelectedItem.Text;
if (cat!="") {
Session["category"] = category.SelectedItem.Text;
}
else {
Session["category"] = "";
}
yea = year.SelectedItem.Text;
if (yea!="") {
Session["year"] = year.SelectedItem.Text;
}
else {
Session["year"] = "";
}
reg = region.SelectedItem.Text;
if (reg!="") {
Session["region"] = region.SelectedItem.Text;
}
else {
Session["region"] = "";
}
cou = country.SelectedItem.Text;
if (cou!="") {
Session["country"] = region.SelectedItem.Text;
}
else {
Session["country"] = "";
}
app = appellation.SelectedItem.Text;
if (app!="") {
Session["appellation"] = appellation.SelectedItem.Text;

}
else {
Session["appellation"] = "";
}


//Session["color"] = color.SelectedItem.Text;
// Session["category"] = category.SelectedItem.Text;
//Session["price"] = price.SelectedIndex;
// Session["year"] = year.SelectedItem.Text;





Response.Redirect("winelist.aspx");



}
void emailoffer(Object sender, System.EventArgs e)
{



}
</script>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive">
<title>Untitled Page</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
.style2 {font-size: 9px}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<p align="center"><img src="e2.jpg" width="694"
height="209"></p>
<table width="81%" height="203" border="0">
<tr height="206">
<td width="54%" height="206"> <div
align="center">Shop the largest online assortment of wines from around the
world.From exciting new wines to monthly best sellers, you'll find
greattasting wines for any occasion. </div></td>
<td width="46%" height="206"><img src="top1.gif" width="229"
height="170"></td>
</tr>
</table>
<table width="769" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="759"><hr noshade></td>
</tr>
</table>
<p> </p>
<form runat="server">
Category: <asp:DropDownList id="category" runat="server">
<asp:ListItem Text=""/>
<asp:ListItem Text="Arneis"/>
<asp:ListItem Text="Barbera"/>
<asp:ListItem Text="Bordeaux"/>
<asp:ListItem Text="Cabernet Sauvignon"/>

<asp:ListItem Text="Chardonnay"/>
<asp:ListItem Text="Coastal South Africa"/>

<asp:ListItem Text="Colchagua"/>
<asp:ListItem Text="Corvina"/>
<asp:ListItem Text="Fortified Blend"/>
<asp:ListItem Text="Fume Blanc"/>
<asp:ListItem Text="Gamay"/>
<asp:ListItem Text="Greco"/>
<asp:ListItem Text="Malbec"/>
<asp:ListItem Text="Marsanne"/>
<asp:ListItem Text="Merlot"/>
<asp:ListItem Text="Montepulciano"/>
<asp:ListItem Text="Moscato"/>
<asp:ListItem Text="Muscadet"/>
<asp:ListItem Text="Nebbiolo"/>
<asp:ListItem Text="Pauillac"/>
<asp:ListItem Text="Pinot Blanc"/>
<asp:ListItem Text="Pinot Bianco"/>
<asp:ListItem Text="Pinot Grigio"/>
<asp:ListItem Text="Pinot Gris"/>
<asp:ListItem Text="Pinot Noir"/>
<asp:ListItem Text="Primitivo "/>
<asp:ListItem Text="Red Blend"/>
<asp:ListItem Text="Rhone Valley"/>
<asp:ListItem Text="Riesling "/>
<asp:ListItem Text="Rose Blend "/>
<asp:ListItem Text="Sake"/>
<asp:ListItem Text="Sangiovese"/>
<asp:ListItem Text="Sauvignon Blanc"/>
<asp:ListItem Text="Semillon "/>
<asp:ListItem Text="Shiraz"/>
<asp:ListItem Text="Sparkling Blend "/>
<asp:ListItem Text="Sweet Blend"/>
<asp:ListItem Text="Syrah"/>
<asp:ListItem Text="Tempranillo"/>
<asp:ListItem Text="White"/>
<asp:ListItem Text="White Blend"/>
<asp:ListItem Text="Viognier"/>
<asp:ListItem Text="Zinfandel"/>
</asp:DropDownList>

Region:
<asp:DropDownList id="region" runat="server">
<asp:ListItem Text=""/>
<asp:ListItem Text="Abruzzi"/>
<asp:ListItem Text="Alsace"/>
<asp:ListItem Text="Andalucia"/>
<asp:ListItem Text="Bordeaux"/>
<asp:ListItem Text="Burgundy"/>
<asp:ListItem Text="California"/>
<asp:ListItem Text="Campania"/>
<asp:ListItem Text="Catalonia"/>
<asp:ListItem Text="Coastal South Africa"/>

<asp:ListItem Text="France"/>
<asp:ListItem Text="Friuli-Venezia Giulia"/>

<asp:ListItem Text="Languedoc-Roussillon"/>

<asp:ListItem Text="La Rioja"/>
<asp:ListItem Text="Loire Valley"/>
<asp:ListItem Text="Lombardy"/>
<asp:ListItem Text="Madeira"/>
<asp:ListItem Text="Maule Valle"/>
<asp:ListItem Text="Mendoza"/>
<asp:ListItem Text="New South Wales"/>

<asp:ListItem Text="Oregon"/>
<asp:ListItem Text="Paarl"/>
<asp:ListItem Text="Piedmont"/>
<asp:ListItem Text="Puglia"/>
<asp:ListItem Text="Rapel"/>
<asp:ListItem Text="Rhone Valley"/>
<asp:ListItem Text="Sake"/>
<asp:ListItem Text="Sicily"/>
<asp:ListItem Text="Southern"/>
<asp:ListItem Text="South Island, NZ"/>

<asp:ListItem Text="South Africa"/>
<asp:ListItem Text="South Australia "/>

<asp:ListItem Text="Trentino-Alto Adige"/>

<asp:ListItem Text="Tuscany"/>
<asp:ListItem Text="Veneto"/>
<asp:ListItem Text="Vin de Pays"/>
<asp:ListItem Text="Washington"/>
<asp:ListItem Text="Western Australia"/>

</asp:DropDownList>
Country:

<asp:DropDownList id=country runat=server>
<asp:ListItem Text=""/>
<asp:ListItem Text="Argentina"/>
<asp:ListItem Text="Australia"/>
<asp:ListItem Text="Chile"/>
<asp:ListItem Text="France"/>
<asp:ListItem Text="Italy"/>
<asp:ListItem Text="Japan"/>
<asp:ListItem Text="New Zealand"/>
<asp:ListItem Text="Spain"/>
<asp:ListItem Text="South Africa"/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top