Request.ServerVariables and master page

D

David C

I have a master page where I want to set a Label at the top of each page
that uses this master to a value based on the web page it is opening. Below
is some code from the master aspx and the page_load from the aspx.vb to help
with this problem. I am trying to set the value of LblHead.Text and it is
not working. Any help is appreciated.

David

Below is the label in the Master Page.

<form id="form1" runat="server">
<asp:Label ID="LblHead" runat="server" Text="Open Orders (Default
Text)" ForeColor="Blue" Font-Size="14"></asp:Label>

I also tried it in here (below) in the master but it did not work either.

<asp:ContentPlaceHolder id="head" runat="server">
<asp:Label ID="Label1" runat="server" Text="Open Orders (Default
Text)" ForeColor="Blue" Font-Size="14"></asp:Label>
</asp:ContentPlaceHolder>

Below is the OrdersMaster.master.vb Page_Load where I am trying to set the
value of LblHead.Text

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Request.ServerVariables("SCRIPT_NAME").ToString Is Nothing
Then
Dim strScript As String =
Request.ServerVariables("SCRIPT_NAME").ToString

If InStr(strScript, "OpenOrders") > 0 Then
LblHead.Text = "Currently Open Orders"
ElseIf InStr(strScript, "Estimates") > 0 Then
ElseIf InStr(strScript, "ClosedOrders") > 0 Then
ElseIf InStr(strScript, "Parts") > 0 Then
Else
End If
Else
LblHead.Text = "Currently Open Orders"

End If
End Sub
 
C

Chris Salter

It looks like your conditional statement is failing, i would try
'Get the script path Eg. /directory/OpenOrders.aspx
Dim pth = Request.Path

'Strip it down a little Eg. OpenOders.aspx
Dim scrpt As String = pth.Substring(pth.LastIndexOf("/") + 1)

'Remove the extension Eg. OpenOrders
scrpt = scrpt.Remove(scrpt.LastIndexOf("."))

'Now run conditions
If scrpt.Contains("OpenOrders") Then

End If
 
D

David C

It turned out that the calling page was using Server.Transfer and when I
changed it to Response.Redirect then the ServerVariables were picked up.
Thanks.

David
 

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,780
Messages
2,569,611
Members
45,284
Latest member
NicholeDum

Latest Threads

Top