files name in asp.net and vb.net - asp.net

I have .aspx and .vb files. The name of it are: SA_Setup.aspx and SA_Setup.vb.
The 1st 10 lines of the code in SA_Setup.aspx file is:
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="SA_Setup.aspx.vb" Inherits="SA_Setup" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link id="Link2" rel="Stylesheet" href="~/Common/OrgSelfAssessment.css" type="text/css"
media="screen" runat="server" />
</asp:Content>
And the 1st 10 lines of code in SA_Setup.aspx.vb file is:
Imports System.Data
Imports GlobalModule
Partial Class SA_Setup
Inherits System.Web.UI.Page
Dim dalGM As GlobalModule
Dim dalSelfAssessment As New SelfAssessmentSetUp
Dim dalSurveyAdmin As New SurveyAdmin
Dim dalClientAdmin As New ClientAdmin
Protected Overrides Sub InitializeCulture()
Try
Dim strCul As String : strCul = Session("Culture")
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(strCul)
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(strCul)
Catch ex As Exception
Response.Redirect("~/Error/ErrorPage.aspx?type=SessionTimedOut&ui=" & Request.QueryString("ui"), True) : Exit Sub
End Try
End Sub
Now, I have changed the files name to SA_Setup_MPHLB.aspx and SA_Setup_MPHLB.aspx.vb. I am wondering what changes do I need to do in the codes above after changing the files name. As per my understanding, I have made the following changes:
In .aspx file (SA_Setup_MPHLB.aspx):
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="SA_Setup_MPHLB.aspx.vb" Inherits="SA_Setup_MPHLB" %>
In .aspx.vb file (SA_Setup_MPHLB.aspx.vb):
Partial Class SA_Setup_MPHLB
Just checking if the changes I have did is right or is there any place I have to do the changes ?

If you are able to successfully rebuild the project after name changes, you may not need to do anything else. If you are getting any error, it will surely suggest you what to do next.

Related

Phantom VB errors in an ASPX file

I have an aspx file containing some VB code:
<%# Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<%# Import Namespace="System.IO" %>
<%# Import Namespace="XXX.Email" %>
<%# Import Namespace="XXX.Functions" %>
<%# Import Namespace="XXX.Rtf" %>
<%# Import Namespace="XXXDBTools" %>
<%# Import Namespace="XXXDBTools.DBFunctions" %>
<%# Import Namespace="XXXStrTools.StrFunctions" %>
<script runat="server">
Dim strToResult
Dim errorMessage
Dim errorMessageFor
Dim referralEmailStr
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
...
End Sub
</script>
<html>
<head>
<title><%=Request.Cookies("State").Value%> Request a Placement</title>
...
</head>
...
</html>
Now I see compile errors on the Request.Cookies("State").Value line, for code that doesn't even exist on this page!
If I delete the line where I'm checking for the state cookie, I still get the same errors, but at the end of the Sub Page_Init I declared above.
The variables mentioned in the errors (such as myTemp and lfyCompanyInfoDSN) do not even exist on this page, so I'm perplexed as to how I could be getting these errors...
Turns out at the very bottom of the <html> tag I had some lines such as this in a script:
set drIntakeWorker = Nothing
Which is not valid because the set keyword is not allowed in VB.NET. Somehow this error was percolating up and screwing up the entire page...

How can I access objects in the code-behind of ASP.NET in the Markup?

I have the following event handling code:
Public Class Details
Inherits System.Web.UI.Page
Public veh As Vehicle
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim id As Integer = Request("id")
veh = New DataRepository().vehicles.get(id)
End Sub
End Class
And have tried to access it in my markup like so:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Added.aspx.vb" Inherits="Auto_Dealer_Website.Added" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% veh.color()%>
</asp:Content>
but the compiler won't recognize it. What am I missing? How do I reference my veh object?
Solved
Can't reference the CodeBehind without first building the project.
Add the equals sign to output the variable:
<%= veh.make %>

Parser Error in Namespace?

I have a webpage that was built using the All In One style (the VB in the page with the HTML), and I have been asked to separate them.
This is how Default.aspx starts out:
<%# Import Namespace="System.Net" %>
<%# Import Namespace="System.IO" %>
<%# Import Namespace="System.Configuration" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.OleDb" %>
<%# Import Namespace="System.Data.SqlClient" %>
<%# Import Namespace="System.Globalization" %>
<%# Import Namespace="System.Security" %>
<html>
<head>
<title>View an Activity (AFE)</title>
<script language="VB" runat="server">
Private m_url1, m_url2, m_downloadText, txtSupplementPage, txtExcerpt, SearchLocation, SearchLocation2, SearchLocation3, SearchLocationOrig As String
Private myTotal1, myTotal2 As Double
Private m_credentials As CredentialCache
' Start the initial page
Protected Sub Page_Load(sender As Object, e As EventArgs)
m_credentials = New CredentialCache()
If Not IsPostBack Then
It goes on. This is just to show you what I'm doing.
I created a new, similar file called that Default2.aspx that includes the Page directive, specifies the CodeBehind file, and the namespace (Inherits). Then I took the VB code out:
<%# Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="app2._Default" %>
<!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>View an Activity (AFE)</title>
Since Default.aspx did not use a Code Behind file, I named my new Code Behind file Default.aspx.vb.
I created a new _Default with Namespace app2 within this Code Behind file, and I copied all of the VB from Default.aspx into it:
Namespace app2
Public Class _Default
Inherits System.Web.UI.Page
Inherits System.Net
Inherits System.IO
Inherits System.Configuration
Inherits System.Data
Inherits System.Data.OleDb
Inherits System.Data.SqlClient
Inherits System.Globalization
Inherits System.Security
Private m_url1, m_url2, m_downloadText, txtSupplementPage, txtExcerpt, SearchLocation, SearchLocation2, SearchLocation3, SearchLocationOrig As String
Private myTotal1, myTotal2 As Double
Private m_credentials As CredentialCache
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
m_credentials = New CredentialCache()
If Not IsPostBack Then
I am trying to give enough code that everyone can see the starting points and where I am now.
I got the two new files uploaded to the web server, and then browsed to them to see how they would look.
However, now when I try to display Default2.aspx in the browser, I get this Parser Error:
Parser Error Message: Could not load type 'app2._Default'.
Source Error:
Line 1: <%# Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="app2._Default" %>
Line 2:
Line 3:
What have I messed up?
For a web site: Change CodeBehind to CodeFile.
<%# Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="app2._Default" %>
For a web application: Add the name of the web project to the Inherits attribute.
<%# Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="nameOfYourWebProject.app2._Default" %>
Also, the _Default class you provided, you can only have one Inherits, I think you meant to add them as Imports on the top of the page.

My web control doesn't appear in my web page in a different folder

My web control doesn't appear in my web page in a different folder,
However it works in another web page in the same location.
My source code is like this :
..
<%Register src="~/UI/Human/HumanUserControl.wuc" TagPrefix="uc1"
TagName="HumanUserControl"/>
...
<uc1:HumanUserControl runat="Server" id="HumanUserControl"/>
...
Error:
Request is not available in this context
The syntax on your Register tag is incorrect. And I'm not sure why you're using a ".wuc" extension instead of the default ".ascx".
You need matching <% %> tags, like so:
<%# Register Src="~/UI/Human/HumanUserControl.wuc" TagPrefix="uc1" TagName="HumanUserControl" %>
If you delete the <%Register .../> and <uc1 .../> tags from your page completely, then in Visual Studio, drag-and-drop the user control from the Solution Explorer directly onto your page wherever you want the control to appear, it will automatically add the correct Register and user control tags for you.
If this doesn't clear things up, then provide more detailed error information, including the code where the exception is thrown.
The following works just fine:
~/UI/Human/HumanUserControl.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="HumanUserControl.ascx.cs" Inherits="UserControlTest.UI.Human.HumanUserControl" %>
<asp:Label ID="lblTest" runat="server" />
~/UI/Human/HumanUserControl.ascx.cs
namespace UserControlTest.UI.Human
{
public partial class HumanUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblTest.Text = Request.Browser.Browser;
}
}
}
~/Default.aspx
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UserControlTest._Default" %>
<%# Register Src="~/UI/Human/HumanUserControl.ascx" TagPrefix="uc1" TagName="HumanUserControl" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<uc1:HumanUserControl runat="server" id="HumanUserControl" />
</asp:Content>

Using ASPX Web User Control with Visual Studio 2010

I am trying to implement a Web User Control into one of my APSX pages but keep getting the following warning:
Element 'IntFilter' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.
The user control is defined in the same web project as the aspx page.
Question:
How do I resolve this warning (I do not want to move the control to a separate project)?
Also, what do I need to do to enable IntelliSense for this control so I can set its FilterTypeSelection property from ASPX?
Code for "~/FilterControls/IntFilter.ascx"
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="IntFilter.ascx.vb" Inherits="StaffSupport.Filters.IntegerFilter" %>
<asp:DropDownList ID="typeFilterDropDownList" runat="server">
<asp:ListItem Selected="True" Text ="Any" Value="-1" />
<asp:ListItem Selected="False" Text ="Equal" Value= "0" />
</asp:DropDownList><br />
<asp:TextBox ID="TextBox1" runat="server" /><asp:CheckBox ID="CheckBox1" runat="server" Text="Inclusive" /><br />
<asp:TextBox ID="TextBox2" runat="server" /><asp:CheckBox ID="CheckBox2" runat="server" Text="Inclusive" /><br />
Code for "~/FilterControls/IntFilter.ascx.vb"
Namespace Filters
Public Class IntegerFilter
Inherits System.Web.UI.UserControl
Public Enum NumberFilterTypes As SByte
Any = -1
Equals = 0
End Enum
Public Property FilterTypeSelection As NumberFilterTypes
Get
Dim value As SByte
If Not Integer.TryParse(typeFilterDropDownList.SelectedValue, value) Then
value = -1
End If
Return CType(value, NumberFilterTypes)
End Get
Set(value As NumberFilterTypes)
typeFilterDropDownList.SelectedValue = CSByte(value)
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
End Namespace
Code for "OpenCases.aspx"
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/StaffSite.Master" CodeBehind="OpenCases.aspx.vb" Inherits="StaffSupport.OpenCases" %>
<%# Register TagPrefix="filters" TagName="IntFilter" src="~/FilterControls/IntFilter.ascx" %>
<asp:Content ID="bodyContent" ContentPlaceHolderID="cphBody" runat="server">
ID<br />
<filters:IntFilter ID="IntFilter1" runat="server" />
</asp:Content>
Code for "OpenCases.aspx.vb"
Public Class OpenCases
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.ViewStateMode = UI.ViewStateMode.Disabled
End Sub
Update 2012/02/21:
Fixed the "filters" vs "filter" miss match.
Also of note, if you drag the control from the Solution Explorer to the page in Design view it will add the references you need (though it was still generating the warning for me). If you drag it to the page in source view it will add an a tag with a href to the element.
Update 2012/02/21 b:
Found the solution, see my answer below.
Apparently you have to reference both the ASCX page and the assembly.
If you drag the ASCX page from the "Solution Explorer" window to the Design view for the page you are editing it will add the reference for the ASCX page, but you will have to add the assembly reference manually.
OpenCases.aspx
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/StaffSite.Master" CodeBehind="OpenCases.aspx.vb" Inherits="StaffSupport.OpenCases" %>
<%# Register Assembly="StaffSupport" Namespace="StaffSupport.Filters" TagPrefix="filters" %><%-- Assembly Reference --%>
<%# Register TagPrefix="filters" TagName="IntFilter" src="~/FilterControls/IntFilter.ascx" %>
<asp:Content ID="bodyContent" ContentPlaceHolderID="cphBody" runat="server">
ID<br />
<filters:IntFilter ID="IntFilter1" runat="server" />
</asp:Content>
Note: beware of object type collisions. For example the following would also work:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/StaffSite.Master" CodeBehind="OpenCases.aspx.vb" Inherits="StaffSupport.OpenCases" %>
<%# Register Assembly="StaffSupport" Namespace="StaffSupport.Filters" TagPrefix="pre1" %><%-- Assembly Reference --%>
<%# Register TagPrefix="pre2" TagName="IntFilter" src="~/FilterControls/IntFilter.ascx" %>
<asp:Content ID="bodyContent" ContentPlaceHolderID="cphBody" runat="server">
ID<br />
<pre1:IntFilter ID="IntFilter1" runat="server" />
</asp:Content>
This is why it started working for me Friday after I posted this, I had added a custom control which implemented System.Web.UI.WebControls.TextBox so I could drag and drop it from the Toolbox. Since it was in the same namespace the control added the assembly reference when it added the control to the page.
Note: if you are referencing dll files which are contained in your project then you may need to remove the page registrations, build, then add the page registrations back. Otherwise the compiler may complain that the dll files are not in the bin.
Update: 2013/04/18
It appears you only need to add the assembly reference if the UserControl is not defined in the same namespace.
If the parrent is defined in Proj.Presentation and the UserControl is defined in Proj.Presentation then you should not need the assembly reference.
If the parrent is defined in Proj.Page and the UserControl is defined in Proj.Page.UserControl then you should not need the assembly reference.
If the parrent is defined in Proj.Page and the UserControl is defined in Proj.UserControl then you need the assembly reference.
The control is declared as:
<%# Register TagPrefix="filters"
and in the markup
<filter:IntFilter
These must match.
You are registering a different prefix from the one you're attempting to use.
You can either change this:
<filter:IntFilter ID="IntFilter1" runat="server" />
to this:
<filters:IntFilter ID="IntFilter1" runat="server" />
Or change this:
<%# Register TagPrefix="filters" TagName="IntFilter"
to this:
<%# Register TagPrefix="filter" TagName="IntFilter"
Close Visual Studio, delete the schema cache, and re-open Visual Studio. You can find the schemas under something like:
C:\Users\Pavel\AppData\Roaming\Microsoft\VisualStudio\10.0\ReflectedSchemas
It is safe to delete all files in this folder.
Delete the contents of that above folder, and all is well.

Resources