|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Request.ServerVariables and master pagethat 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 "David C" <dlch***@lifetimeinc.com> wrote in message "Not working" doesn't tell the group very much - in what way(s) is it not news:eQPuwQR8JHA.1380@TK2MSFTNGP02.phx.gbl... > I am trying to set the value of LblHead.Text and it is not working. working...? > Any help is appreciated. When you step through the code in debug mode, how far does it get...?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 Show quoteHide quote "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message news:er3gTdR8JHA.3544@TK2MSFTNGP03.phx.gbl... > "David C" <dlch***@lifetimeinc.com> wrote in message > news:eQPuwQR8JHA.1380@TK2MSFTNGP02.phx.gbl... > >> I am trying to set the value of LblHead.Text and it is not working. > > "Not working" doesn't tell the group very much - in what way(s) is it not > working...? > > >> Any help is appreciated. > > When you step through the code in debug mode, how far does it get...? > > > -- > Mark Rae > ASP.NET MVP > http://www.markrae.net "David C" <dlch***@lifetimeinc.com> wrote in message [top-posting corrected]news:ueY63rS8JHA.2788@TK2MSFTNGP05.phx.gbl... Show quoteHide quote >>> I am trying to set the value of LblHead.Text and it is not working. >> >> "Not working" doesn't tell the group very much - in what way(s) is it not >> working...? >> >>> Any help is appreciated. >> >> When you step through the code in debug mode, how far does it get...? > > 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. 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 Show quoteHide quote "David C" <dlch***@lifetimeinc.com> wrote in message news:eQPuwQR8JHA.1380@TK2MSFTNGP02.phx.gbl... >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 > Thanks Chris, I like your code sample better.
David Show quoteHide quote "Chris Salter" <chris.sal***@anetics.co.uk> wrote in message news:A5437373-9665-44CA-8E5F-DACEBFBC1006@microsoft.com... > 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 > > > > "David C" <dlch***@lifetimeinc.com> wrote in message > news:eQPuwQR8JHA.1380@TK2MSFTNGP02.phx.gbl... >>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 >> > |
|||||||||||||||||||||||