Converting from ASP to ASP.net | Member | | Join Date: Jul 2007 Location: Toronto, Canada
Posts: 84
| |
Hi,
I am trying to convert my classic asp code to .net. I have created user controls and put following code in one of the user controls. -
<div id="buttons">
-
<ul id="topImages" class="menu" style="margin-left: -2px;">
-
<li>
-
<img id="home" alt="Home" class="top" onclick="javascript:location.href='default.asp'" onmouseout="changeImage(this.id,'home_top<%=home%>.png');" onmouseover="changeImage(this.id,'home_top_over.png');" src="http://bytes.com/images/home_top<%=home%>.png" ></li>
-
<li><img id="web" alt="Services" class="top" onclick="javascript:location.href='services.asp'" onmouseout="changeImage(this.id,'services_top<%=services%>.png');" onmouseover="changeImage(this.id,'services_top_over.png');" src="http://bytes.com/images/services_top<%=services%>.png" >
-
</li>
-
</ul></div>
and if my home page I have some code like this. -
-
<%@ Register TagPrefix="uc" TagName="topMenu" Src="~/inc/topMenu.ascx" %>
-
-
<%
-
Dim home, services As String
-
-
home = "_selected"
-
services = ""
-
%>
-
All my user controls are in a sub folder called "inc". In the topMenu user control it is giving me errors that it cannot recognize home and services variable.
What I need to do to make it work.
Thanks
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North
Posts: 5,137
| | | re: Converting from ASP to ASP.net
Could you please post the first line in your ASP page so that I can see how your project's configured.
If your project's configured to have 2 files created for your page (the ASP code and the VB.NET code in separate files) then you'll have to move the code in the <% %> to the VB.NET Code file. In this case your fist line in the page will have a CodeBehind attribute pointing to the VB file that should contain the page's VB.NET code. For example: - <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="ScratchPad.WebForm1" %>
If your project's not configured this way, then I believe you need to include script tags (<script runat="server"><script>) instead of the <% %>.
For example: -
<%@ Page Language="VB" %>
-
<script runat="server">
-
Sub Button1_Click(ByVal sender As Object, _
-
ByVal e As System.EventArgs)
-
Label1.Text = "Server click handler called."
-
End Sub
-
</script>
-
-
<body>
-
<form id="form1" runat="server">
-
<asp:Button ID="Button1" Runat="server"
-
OnClick="Button1_Click"
-
OnClientClick="return confirm('Ready to submit.')"
-
Text="Test Client Click" />
-
<br />
-
<asp:Label ID="Label1" Runat="server" text="" />
-
</form>
-
</body>
-
</html>
Just post your first line and we'll be able to help you better.
-Frinny
| | Member | | Join Date: Jul 2007 Location: Toronto, Canada
Posts: 84
| | | re: Converting from ASP to ASP.net
This is the default.aspx code - <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
-
<%@ Register TagPrefix="uc" TagName="homeText" Src="~/inc/homeText.ascx" %>
-
<%@ Register TagPrefix="uc" TagName="pageHeader" Src="~/inc/header.ascx" %>
-
<%@ Register TagPrefix="uc" TagName="leftMenu" Src="~/inc/leftMenu.ascx" %>
-
<%@ Register TagPrefix="uc" TagName="footer" Src="~/inc/footer.ascx" %>
-
<%@ Register TagPrefix="uc" TagName="headTags" Src="~/inc/headTags.ascx" %>
-
<%@ Register TagPrefix="uc" TagName="topMenu" Src="~/inc/topMenu.ascx" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Omair Tech & Designs</title>
-
<uc:headTags ID="headTags" runat="server" />
-
</head>
-
-
<%
-
Dim home, solutions, services, support, about, contact As String
-
-
home = "_selected"
-
solutions = ""
-
services = ""
-
support = ""
-
about = ""
-
contact = ""
-
%>
-
-
<body>
-
<form id="userControlForm" runat="server">
-
<table id="mainTable" align="center" border="0">
-
<tbody>
-
<tr>
-
<td>
-
<uc:pageHeader ID="pageHeader" runat="server" />
-
<uc:topMenu id="topMenu" runat="server" />
-
-
<table id="mainContainer" border="0" cellspacing="0px">
-
<tbody>
-
<tr>
-
<!-- Left Menu -->
-
<uc:leftMenu ID="leftMenu" runat="server" />
-
-
<td id="mainContainerTextArea" valign="top">
-
<uc:homeText id="homeText" runat="server" />
-
-
</td>
-
</tr>
-
</tbody>
-
</table>
-
</td>
-
</tr>
-
<uc:footer ID="footer" runat="server" />
-
</tbody>
-
</table>
-
</form>
-
</body>
-
</html>
And this is the topMenu.ascx code. Every user control is in "inc" folder. - <%@ Control Language="VB" AutoEventWireup="false" CodeFile="topMenu.ascx.vb" Inherits="inc_topMenu" %>
-
-
<div id="buttons">
-
<ul id="topImages" class="menu" style="margin-left: -2px;">
-
<li>
-
<img id="home" alt="Home" class="top" onclick="javascript:location.href='default.aspx'" onmouseout="changeImage(this.id,'home_top<%=home%>.png');" onmouseover="changeImage(this.id,'home_top_over.png');" src="images/home_top<%=home%>.png" >
-
</li>
-
<li>
-
<img id="web" alt="Services" class="top" onclick="javascript:location.href='services.aspx'" onmouseout="changeImage(this.id,'services_top<%=services%>.png');" onmouseover="changeImage(this.id,'services_top_over.png');" src="images/services_top<%=services%>.png" >
-
</li>
-
<li>
-
<img id="app" alt="Solutions" class="top" onclick="javascript:location.href='solutions.aspx'" onmouseout="changeImage(this.id,'solutions_top<%=solutions%>.png');" onmouseover="changeImage(this.id,'solutions_top_over.png');" src="images/solutions_top<%=solutions%>.png" >
-
</li>
-
<li>
-
<img id="network" alt="Support" class="top" onclick="javascript:location.href='support.aspx'" onmouseout="changeImage(this.id,'support_top<%=support%>.png');" onmouseover="changeImage(this.id,'support_top_over.png');" src="images/support_top<%=support%>.png" >
-
</li>
-
<li>
-
<img id="about" alt="About us" class="top" onclick="javascript:location.href='aboutus.aspx'" onmouseout="changeImage(this.id,'about_top<%=about%>.png');" onmouseover="changeImage(this.id,'about_top_over.png');" src="images/about_top<%=about%>.png" >
-
</li>
-
<li>
-
<img id="consult" alt="Contact Us" class="top" onclick="javascript:location.href='contact.aspx'" onmouseout="changeImage(this.id,'contact_top<%=contact%>.png');" onmouseover="changeImage(this.id,'contact_top_over.png');" src="images/contact_top<%=contact%>.png" >
-
</li>
-
</ul>
-
</div>
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North
Posts: 5,137
| | | re: Converting from ASP to ASP.net
When you're viewing the ASPX page (in design view not the ASPX code)...double click on the page.
This will open the Default.aspx.vb.
Your code belongs in the Default.aspx.vb file, not in the Default.aspx file.
You need to move the following into the .vb file: -
Dim home, solutions, services, support, about, contact As String
-
-
home = "_selected"
-
solutions = ""
-
services = ""
-
support = ""
-
about = ""
-
contact = ""
I would recommend using proper scope for your variables. So, in your Default.aspx.vb file you should have something like: -
Partial Public Class _Default
-
Inherits System.Web.UI.Page
-
-
Private solutions, services, support, about, contact As String
-
Private home As String = "_selected"
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
End Sub
-
End Class
-
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North
Posts: 5,137
| | | re: Converting from ASP to ASP.net
Oh wait a sec!
The variables that you've defined in your Default page will not be accessible in your UserControl
You either need to move these variables to the User Control's .vb file....or you need to place them into the web.config file so that they can be accessed throughout every UserControl or Page in the project.
| | Member | | Join Date: Jul 2007 Location: Toronto, Canada
Posts: 84
| | | re: Converting from ASP to ASP.net
Actually I was able to fix it using following way -
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="topMenu.ascx.vb" Inherits="inc_topMenu" %>
-
-
<%
-
-
Dim home, solutions, services, support, about, contact, selectedPage As String
-
-
selectedPage = Request.Url.ToString
-
selectedPage = selectedPage.Substring(selectedPage.LastIndexOf("/") + 1)
-
-
Select Case selectedPage
-
Case "default.aspx"
-
home = "_selected"
-
Case "solutions.aspx"
-
solutions = "_selected"
-
Case "services.aspx"
-
services = "_selected"
-
Case "support.aspx"
-
support = "_selected"
-
Case "about.aspx"
-
about = "_selected"
-
Case "contact.aspx"
-
contact = "_selected"
-
End Select
-
%>
-
-
<div id="buttons">
-
<ul id="topImages" class="menu" style="margin-left: -2px;">
-
<li>
-
<img id="home" alt="Home" class="top" onclick="javascript:location.href='default.aspx'" onmouseout="changeImage(this.id,'home_top<%=home%>.png');" onmouseover="changeImage(this.id,'home_top_over.png');" src="images/home_top<%=home%>.png" >
-
</li>
-
<li>
-
<img id="web" alt="Services" class="top" onclick="javascript:location.href='services.aspx'" onmouseout="changeImage(this.id,'services_top<%=services%>.png');" onmouseover="changeImage(this.id,'services_top_over.png');" src="images/services_top<%=services%>.png" >
-
</li>
-
<li>
-
<img id="app" alt="Solutions" class="top" onclick="javascript:location.href='solutions.aspx'" onmouseout="changeImage(this.id,'solutions_top<%=solutions%>.png');" onmouseover="changeImage(this.id,'solutions_top_over.png');" src="images/solutions_top<%=solutions%>.png" >
-
</li>
-
<li>
-
<img id="network" alt="Support" class="top" onclick="javascript:location.href='support.aspx'" onmouseout="changeImage(this.id,'support_top<%=support%>.png');" onmouseover="changeImage(this.id,'support_top_over.png');" src="images/support_top<%=support%>.png" >
-
</li>
-
<li>
-
<img id="about" alt="About us" class="top" onclick="javascript:location.href='aboutus.aspx'" onmouseout="changeImage(this.id,'about_top<%=about%>.png');" onmouseover="changeImage(this.id,'about_top_over.png');" src="images/about_top<%=about%>.png" >
-
</li>
-
<li>
-
<img id="consult" alt="Contact Us" class="top" onclick="javascript:location.href='contact.aspx'" onmouseout="changeImage(this.id,'contact_top<%=contact%>.png');" onmouseover="changeImage(this.id,'contact_top_over.png');" src="images/contact_top<%=contact%>.png" >
-
</li>
-
</ul>
-
</div>
-
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North
Posts: 5,137
| | | re: Converting from ASP to ASP.net
Yeah, you had to move the variables into the correct place to work.
I would still recommend properly using the .vb file associated with the aspx page.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|