WWW in URL breaks ASP .Net Script ?
-
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 -
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, MitchWhat 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 )
-
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 )
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 -
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, MitchI 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