473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting from ASP to ASP.net

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.

Expand|Select|Wrap|Line Numbers
  1. <div id="buttons">
  2. <ul id="topImages" class="menu" style="margin-left: -2px;">
  3. <li>
  4. <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>
  5. <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" >
  6. </li>
  7. </ul></div>
and if my home page I have some code like this.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Register TagPrefix="uc" TagName="topMenu" Src="~/inc/topMenu.ascx" %>
  3.  
  4. <%
  5.     Dim home, services As String
  6.  
  7.     home = "_selected"
  8.     services = ""
  9. %>
  10.  
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
Jun 26 '09 #1
6 2330
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. <%@ 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:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" %>
  2. <script runat="server">
  3.     Sub Button1_Click(ByVal sender As Object, _
  4.         ByVal e As System.EventArgs)
  5.         Label1.Text = "Server click handler called."
  6.     End Sub
  7. </script>
  8.  
  9. <body>
  10.   <form id="form1" runat="server">
  11.     <asp:Button ID="Button1" Runat="server" 
  12.       OnClick="Button1_Click" 
  13.         OnClientClick="return confirm('Ready to submit.')" 
  14.         Text="Test Client Click" />
  15.     <br />
  16.     <asp:Label ID="Label1" Runat="server" text="" />
  17.   </form>
  18. </body>
  19. </html>
Just post your first line and we'll be able to help you better.

-Frinny
Jun 26 '09 #2
This is the default.aspx code

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2. <%@ Register TagPrefix="uc" TagName="homeText" Src="~/inc/homeText.ascx" %>
  3. <%@ Register TagPrefix="uc" TagName="pageHeader" Src="~/inc/header.ascx" %>
  4. <%@ Register TagPrefix="uc" TagName="leftMenu" Src="~/inc/leftMenu.ascx" %>
  5. <%@ Register TagPrefix="uc" TagName="footer" Src="~/inc/footer.ascx" %>
  6. <%@ Register TagPrefix="uc" TagName="headTags" Src="~/inc/headTags.ascx" %>
  7. <%@ Register TagPrefix="uc" TagName="topMenu" Src="~/inc/topMenu.ascx" %>
  8.  
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10.  
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head runat="server">
  13. <title>Omair Tech &amp; Designs</title>
  14. <uc:headTags ID="headTags" runat="server" />
  15. </head>
  16.  
  17. <%
  18.     Dim home, solutions, services, support, about, contact As String
  19.  
  20.     home = "_selected"
  21.     solutions = ""
  22.     services = ""
  23.     support = ""
  24.     about = ""
  25.     contact = ""
  26. %>
  27.  
  28. <body>
  29. <form id="userControlForm" runat="server">
  30. <table id="mainTable" align="center" border="0">
  31.     <tbody>
  32.     <tr>
  33.         <td>
  34.         <uc:pageHeader ID="pageHeader" runat="server" />
  35.         <uc:topMenu id="topMenu" runat="server" />
  36.  
  37.         <table id="mainContainer" border="0" cellspacing="0px">
  38.             <tbody>
  39.             <tr>
  40.                 <!-- Left Menu -->
  41.                 <uc:leftMenu ID="leftMenu" runat="server" />
  42.  
  43.                 <td id="mainContainerTextArea" valign="top">
  44.                     <uc:homeText id="homeText" runat="server" />
  45.  
  46.                 </td>
  47.             </tr>
  48.         </tbody>
  49.         </table>
  50.         </td>
  51.     </tr>
  52.     <uc:footer ID="footer" runat="server" />
  53. </tbody>
  54. </table>
  55. </form>
  56. </body>
  57. </html>
And this is the topMenu.ascx code. Every user control is in "inc" folder.

Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="topMenu.ascx.vb" Inherits="inc_topMenu" %>
  2.  
  3. <div id="buttons">
  4.     <ul id="topImages" class="menu" style="margin-left: -2px;">
  5.         <li>
  6.             <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" >
  7.         </li>
  8.         <li>
  9.             <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" >
  10.         </li>
  11.         <li>
  12.             <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" >
  13.         </li>
  14.         <li>
  15.             <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" >
  16.         </li>
  17.         <li>
  18.             <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" >
  19.         </li>
  20.         <li>
  21.             <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" >
  22.         </li>
  23.     </ul>
  24. </div>
Jun 26 '09 #3
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1.     Dim home, solutions, services, support, about, contact As String
  2.  
  3.     home = "_selected"
  4.     solutions = ""
  5.     services = ""
  6.     support = ""
  7.     about = ""
  8.     contact = ""
I would recommend using proper scope for your variables. So, in your Default.aspx.vb file you should have something like:
Expand|Select|Wrap|Line Numbers
  1. Partial Public Class _Default
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Private solutions, services, support, about, contact As String
  5.     Private home As String = "_selected"
  6.  
  7.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.  
  9.     End Sub
  10. End Class
  11.  
Jun 26 '09 #4
Frinavale
9,735 Expert Mod 8TB
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.
Jun 26 '09 #5
Actually I was able to fix it using following way

Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="topMenu.ascx.vb" Inherits="inc_topMenu" %>
  2.  
  3. <%
  4.  
  5.     Dim home, solutions, services, support, about, contact, selectedPage As String
  6.  
  7.     selectedPage = Request.Url.ToString
  8.     selectedPage = selectedPage.Substring(selectedPage.LastIndexOf("/") + 1)
  9.  
  10.     Select Case selectedPage
  11.         Case "default.aspx"
  12.             home = "_selected"
  13.         Case "solutions.aspx"
  14.             solutions = "_selected"
  15.         Case "services.aspx"
  16.             services = "_selected"
  17.         Case "support.aspx"
  18.             support = "_selected"
  19.         Case "about.aspx"
  20.             about = "_selected"
  21.         Case "contact.aspx"
  22.             contact = "_selected"
  23.     End Select
  24. %>
  25.  
  26. <div id="buttons">
  27.     <ul id="topImages" class="menu" style="margin-left: -2px;">
  28.         <li>
  29.             <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" >
  30.         </li>
  31.         <li>
  32.             <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" >
  33.         </li>
  34.         <li>
  35.             <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" >
  36.         </li>
  37.         <li>
  38.             <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" >
  39.         </li>
  40.         <li>
  41.             <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" >
  42.         </li>
  43.         <li>
  44.             <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" >
  45.         </li>
  46.     </ul>
  47. </div>
  48.  
Jun 26 '09 #6
Frinavale
9,735 Expert Mod 8TB
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.
Jun 26 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mustafa | last post by:
Dear sir , I have built my application in visual basic 6.0 and crystal Report8.5 , Now i migrated my application to VB.net using the upgrade wizard.My visual basic form is upgraded to vb.net...
29
by: Armand Karlsen | last post by:
I have a website ( http://www.zen62775.zen.co.uk ) that I made HTML 4.01 Transitional and CSS compliant, and I'm thinking of converting it into XHTML to learn a little about it. Which XHTML variant...
8
by: prabha | last post by:
Hello Everybody, I have to conert the word doc to multiple html files,according to the templates in the word doc. I had converted the word to xml.Also through Exsl ,had finished the multiple...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
by: Mary | last post by:
Hi, Does anyone know of any software out there that would convert an application written in VBScript to either VB.NET or C#/C++ quite quickly for me, or will I have to re-write the application...
2
by: Map Reader | last post by:
Greetings, I am converting an old VB6 application to use .NET. One of the old controls loads icons from the disk and displays them. However, the transparent color turns to blue somewhere in the...
12
by: Frederik Vanderhaeghe | last post by:
Hi, I have a problem converting text to a double. Why doesn't the code work: If Not (txtdocbedrag.Text = "") Then Select Case ddlBedrag.SelectedIndex Case 0 Case 1
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.