Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. WWW in URL breaks ASP .Net Script ?

WWW in URL breaks ASP .Net Script ?

Scheduled Pinned Locked Moved ASP.NET
csharpcssdotnetwpfdesign
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mitch F
    wrote on last edited by
    #1

    Hi, I am using some ASP .Net code to allow the user to change the theme (aka, stylesheet) that my website uses, based on a cookie and an imagebutton. It works fine when the domain url has no "www" in it, but as soon as I place it in the URL, the script does nothing at all. I think it calls a post-back and refreshes the page, but beyond that nothing happens. It works in FireFox, but not in IE, from recent testing. My code is located in the HEAD section of the page, as well. <% Dim nString As String = "<link href=""templates/stylesheet.css"" rel=""stylesheet"" type=""text/css"" />" Dim cString As String = "<link href=""templates/stylesheetC.css"" rel=""stylesheet"" type=""text/css"" />" Dim nImg As String = "images/logo_inverted.png" Dim cImg As String = "images/logo_normal.png" Try Dim themeCookie As String = Request.Cookies("theme").Value If themeCookie = "low" Then Response.Write(nString) imgLogo.Src = nImg ElseIf themeCookie = "high" Then Response.Write(cString) imgLogo.Src = cImg Else Response.Write(nString) imgLogo.Src = nImg End If Catch ex As Exception Response.Write(nString) imgLogo.Src = nImg End Try %> <script runat="server"> Sub highContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "high" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub Sub lowContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "low" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub </script> I have been working on this for a few hours now, and everything that I try doesn't work. My server is also running the .Net Framework 2.0. Any help is appreciated. Thanks, Mitch

    C M 2 Replies Last reply
    0
    • M Mitch F

      Hi, I am using some ASP .Net code to allow the user to change the theme (aka, stylesheet) that my website uses, based on a cookie and an imagebutton. It works fine when the domain url has no "www" in it, but as soon as I place it in the URL, the script does nothing at all. I think it calls a post-back and refreshes the page, but beyond that nothing happens. It works in FireFox, but not in IE, from recent testing. My code is located in the HEAD section of the page, as well. <% Dim nString As String = "<link href=""templates/stylesheet.css"" rel=""stylesheet"" type=""text/css"" />" Dim cString As String = "<link href=""templates/stylesheetC.css"" rel=""stylesheet"" type=""text/css"" />" Dim nImg As String = "images/logo_inverted.png" Dim cImg As String = "images/logo_normal.png" Try Dim themeCookie As String = Request.Cookies("theme").Value If themeCookie = "low" Then Response.Write(nString) imgLogo.Src = nImg ElseIf themeCookie = "high" Then Response.Write(cString) imgLogo.Src = cImg Else Response.Write(nString) imgLogo.Src = nImg End If Catch ex As Exception Response.Write(nString) imgLogo.Src = nImg End Try %> <script runat="server"> Sub highContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "high" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub Sub lowContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "low" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub </script> I have been working on this for a few hours now, and everything that I try doesn't work. My server is also running the .Net Framework 2.0. Any help is appreciated. Thanks, Mitch

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What a disaster. Why would you put this code in the page and not the code behind ? This gives you no control over when it runs, and is nasty/messy. Put the script in your code behind where it belongs, set some break points and then you will be able to work out what's going wrong instead of having to guess.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      M 1 Reply Last reply
      0
      • C Christian Graus

        What a disaster. Why would you put this code in the page and not the code behind ? This gives you no control over when it runs, and is nasty/messy. Put the script in your code behind where it belongs, set some break points and then you will be able to work out what's going wrong instead of having to guess.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        M Offline
        M Offline
        Mitch F
        wrote on last edited by
        #3

        Hi, As suggested, I have moved all of my code into the code-behind file. My head section now looks like: <link rel="stylesheet" id="style" runat="server" /> And my codefile looks like: Partial Class _Default Inherits System.Web.UI.Page Protected Sub highContrast_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles highContrast.Click Response.Cookies("theme").Value = "high" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub Protected Sub lowContrast_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles lowContrast.Click Response.Cookies("theme").Value = "low" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit Dim nString As String = "templates/stylesheet.css" Dim cString As String = "templates/stylesheetC.css" Dim nImg As String = "images/logo_inverted.png" Dim cImg As String = "images/logo_normal.png" Try Dim themeCookie As String = Request.Cookies("theme").Value If themeCookie = "low" Then style.Href = nString imgLogo.Src = nImg ElseIf themeCookie = "high" Then style.Href = cString imgLogo.Src = cImg Else style.Href = nString imgLogo.Src = nImg End If Catch ex As Exception style.Href = nString imgLogo.Src = nImg End Try End Sub End Class However, I am still experiencing the same issue. Do you have any other suggestions? (I have also tried putting my code into Init, Load, and now PreInit, and nothing seems to change the result.) I am beginning to believe this is a problem with IE, because FF works fine. Thanks, Mitch

        1 Reply Last reply
        0
        • M Mitch F

          Hi, I am using some ASP .Net code to allow the user to change the theme (aka, stylesheet) that my website uses, based on a cookie and an imagebutton. It works fine when the domain url has no "www" in it, but as soon as I place it in the URL, the script does nothing at all. I think it calls a post-back and refreshes the page, but beyond that nothing happens. It works in FireFox, but not in IE, from recent testing. My code is located in the HEAD section of the page, as well. <% Dim nString As String = "<link href=""templates/stylesheet.css"" rel=""stylesheet"" type=""text/css"" />" Dim cString As String = "<link href=""templates/stylesheetC.css"" rel=""stylesheet"" type=""text/css"" />" Dim nImg As String = "images/logo_inverted.png" Dim cImg As String = "images/logo_normal.png" Try Dim themeCookie As String = Request.Cookies("theme").Value If themeCookie = "low" Then Response.Write(nString) imgLogo.Src = nImg ElseIf themeCookie = "high" Then Response.Write(cString) imgLogo.Src = cImg Else Response.Write(nString) imgLogo.Src = nImg End If Catch ex As Exception Response.Write(nString) imgLogo.Src = nImg End Try %> <script runat="server"> Sub highContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "high" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub Sub lowContrastBtn(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Response.Cookies("theme").Value = "low" Response.Cookies("theme").Expires = DateTime.Now.AddYears(1) Page.Response.Redirect(Page.Request.Url.ToString, True) End Sub </script> I have been working on this for a few hours now, and everything that I try doesn't work. My server is also running the .Net Framework 2.0. Any help is appreciated. Thanks, Mitch

          M Offline
          M Offline
          Mitch F
          wrote on last edited by
          #4

          I have another small update to make. Inside my Click event handler, I can change the stylesheet by using, style.Href = nString imgLogo.Src = nImg , it just seems like Internet Explorer is refusing to let me set the cookie when I have the WWW in the URL. Is there a setting that I am forgetting to set? Thanks, Mitch

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups