Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name 'Request' is not declared

Status
Not open for further replies.

ironhide1975

Programmer
Feb 25, 2003
451
US
Can someone help a ASP.Net newbie. I have a project that works fine, however when I copy the files to a server and run them I get the following error.

Code:
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: BC30451: Name 'Request' is not declared.

Here is a copy of my source code

Code:
<script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
      Dim PageID As Integer

      PageID = Request.QueryString("PageID")
  
      If PageID = 2 Or PageID = "2" Then
        redbar.Style("color") = "#F0F0F0"
        redbar.BackImageUrl = "i/HM-Tan.jpg"
        TopHeaderBar.ImageUrl = "i/HM-Red.gif"
      Else
        PageID = 3
        redbar.Style("color") = "#F0F0F0"
        redbar.BackImageUrl = "i/HM-Red.gif"
        TopHeaderBar.ImageUrl = "i/H-Default.gif"
      End If
      
      'Response.Write(PageID)
    End Sub
   </script>

Any help is appreciated.

 
Is the code above from an aspx page or a user control? Also, can you supply the contents of your web.config file?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The above code is inline vbscript code from the inside of a web user control. This control is basically my header bar for my website, labeled header.ascx. The web.config file is provided below.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<appSettings>
		<add key="dbconnection" value="server=HDQ-MKT-702;Initial Catalog=FGConnect;UID=work;PWD=work" />
	</appSettings>
	<system.web>

		<!--  DYNAMIC DEBUG COMPILATION
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.
    -->
		<compilation defaultLanguage="vb" debug="true" />

		<!--  CUSTOM ERROR MESSAGES
          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. 
          Add <error> tags for each of the errors you want to handle.

          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running 
           on the local Web server. This setting is recommended for security purposes, so 
           that you do not display application detail information to remote clients.
    -->
		<customErrors mode="Off" />

		<!--  AUTHENTICATION 
          This section sets the authentication policies of the application. Possible modes are "Windows", 
          "Forms", "Passport" and "None"

          "None" No authentication is performed. 
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to 
           its settings for the application. Anonymous access must be disabled in IIS. 
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then 
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    -->
		<authentication mode="Windows" />


		<!--  AUTHORIZATION 
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous 
          (unauthenticated) users.
    -->
		<authorization>
			<allow users="*" />
			<!-- Allow all users -->

			<!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
		</authorization>

		<!--  APPLICATION-LEVEL TRACE LOGGING
          Application-level tracing enables trace log output for every page within an application. 
          Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
          trace information will be displayed at the bottom of each page.  Otherwise, you can view the 
          application trace log by browsing the "trace.axd" page from your web application
          root. 
    -->
		<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />


		<!--  SESSION STATE SETTINGS
          By default ASP.NET uses cookies to identify which requests belong to a particular session. 
          If cookies are not available, a session can be tracked by adding a session identifier to the URL. 
          To disable cookies, set sessionState cookieless="true".
    -->
		<sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:33000"
            sqlConnectionString="data source=MANAPPS2;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
    />

		<!--  GLOBALIZATION
          This section sets the globalization settings of the application. 
    -->
		<globalization requestEncoding="utf-8" responseEncoding="utf-8" />

	</system.web>

</configuration>

 
The above code is inline vbscript code from the inside of a web user control
The request object shouldn't be really be accessed directly from a web user control but if you need to do it server-side use httpContext.Current.Request.

Also, I doubt if the request object is accessible from vbscript (as that is a client-side language) but you may want to check in the vbscript forum if this is true or not (although even if it is, it won't work in non IE browsers).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
If I have an object in the user control that I want to manipulate via a variable, where should I put the request for the variable then? The main page? And if so how do I write it?

PageID = httpContext.Current.Request("PageID")

??


 
You should create a Public Property in the user control and then set that property from the page.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok, can you help me how to do this?

I added this to my user control

Code:
PageID = HttpContext.Current.Request("PageID").ToString()

and this works fine, but when I copy the files to the server I get this error.

Code:
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 15: 
Line 16:       'PageID = Request.QueryString("PageID")
Line 17:       PageID = HttpContext.Current.Request("PageID").ToString()
Line 18:       
Line 19:       If PageID = 2 Or PageID = "2" Then

If I put this code, in my default.aspx page, it doesn't pass it automatically to the user control. Am I missing something to tell the main page to say (hey use this variable in the user control).

Code:
PageID = HttpContext.Current.Request("PageID").ToString()

any examples how to do this is greatily appreciated.

 
ca8msm said:
You should create a Public Property in the user control and then set that property from the page.
So, create a Public Property (along with a local variable)
Code:
    Public Property myString() As String
        Get
            Return _myString
        End Get
        Set(ByVal value As String)
            _myString = value
        End Set
    End Property
    Private _myString As String
Then, simply set the value from the aspx page. The user control can simply use the _myString variable with whatever you've populated it with (i.e. the querystring value).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top