.ascx file question

R

Rob Meade

Hi all,

Still very new to ASP.Net so please bare with me.

I have created several .ascx controls which I have dragged and dropped onto
my page in a table, looks very nice - each of the controls contains HTML
code which is re-used across several pages.

One on the controls places a navigation bar across the page and should tell
the user where they are etc.

When I clicked on 'view code' in VS to add some IF...THEN's for checking the
page they are on against my list of pages they could be on - I received an
error message about the positioning of my code....I am a bit lost...

Here's the code from the control as it is now -working -without what I'd
like to add...

Public Class GreyBar
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
End Class

And here's the HMTL view of the page :

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="GreyBar.ascx.vb" Inherits="eNotifications.GreyBar"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td align="right" bgColor="#dddddd"><font
class="greybarHeadingText"><b>PAGE NAME HERE<b>&nbsp;</font></td>
</tr>
</table>


What I want to do is run something like this (this is probably what I'd have
done in regular ASP)...

If UCase(Request.ServerVariables("SCRIPT_NAME")) = "NOTIFICATION.ASPX" Then

strPageName = "Submit Notification"

End If

Obviously I would have more of these for the other pages too, but this would
then give me the text I want in a variable to then use above perhaps in the
form of :

<%=strPageName%>

etc

But I'm not sure where to place this code - surely it should go into the
..ascx file - in the code behind (.vb) file for it?

Any help would be appreciated...

Regards

Rob
 
R

Rob Meade

...
But I'm not sure where to place this code - surely it should go into the
.ascx file - in the code behind (.vb) file for it?

I have managed to get it to work by adding the following into my .vb file
for the .ascx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Declare variables

Dim aScriptName As Array
Dim strScriptName As String

' Populate script name variable
strScriptName = UCase(Request.ServerVariables("SCRIPT_NAME"))

' Create an array of script name parts
aScriptName = Split(strScriptName, "/")

' Set our script name variable to equal the last item in the array
strScriptName = aScriptName(UBound(aScriptName))

' Begin our page name testing routine

If strScriptName = "LOGOUT.ASPX" Then

lblPageName.Text = "Log Out"

ElseIf strScriptName = "NOTIFICATION.ASPX" Then

lblPageName.Text = "Submit Notification"

End If

End Sub


Seems to work nicely, but if anyone spots any mistakes, ie, I'm going about
this the wrong way please let me know.

Thanks

Rob
 

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

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top