MVC :: Unable To Redirect With Anchor In IE 8
May 14, 2010The line of controller code below works perfect in Firefox and Safari to do a response redirect to an anchor. In IE 8 the response redirect does not return to the anchor.
[Code]....
The line of controller code below works perfect in Firefox and Safari to do a response redirect to an anchor. In IE 8 the response redirect does not return to the anchor.
[Code]....
I am trying to render a simple hyperlink that links to a named anchor within the page, for example:
<a href="#namedAnchor">scroll to down</a>
<a name="namedAnchor">down</a>
The problem is that when I use an ASP.NET control like asp:HyperLink or HtmlAnchor, the href="#namedAnchor" is rendered as href="controls/#namedAnchor" (where controls is the subdirectory where the user control containing the anchor is). Here is the code for the control, using two types of anchor controls, which both have the same problem:
[code]....
I am using the HtmlAnchor or HyperLink class because I want to make changes to other attributes in the code behind. I do not want to introduce a custom web control for this requirement, as the requirement I'm pursuing is not that important enough to justify abandoning the traditional ASP.NET link controls. It seems like I should be able to use the ASP.NET link controls to generate the desired link.
I am trying to redirect to a .aspx page from a controller within my application using following method
[Code]....
[Code]....
[Code]....
I had a problem lately that I managed to have for it 2 solutions and I am wondering which one should I choose. Here the issue : When a user requests my site ( www..com), I am gonna redirect him to (www..com/en) because it is a multilingual site. I am using .NET routing to to that. In the Page_Load of the default.aspx page I check if the language in the Routing Collection is available, I don't redirect. If it is not available I redirect to (www._.com/en). Here is the code :
if (Page.RouteData.Values.Count == 0)
{
if (SessionManager.IsUserAuthenticated)
{
//Redirect To User HomePage for his Main Language
Page.Response.Redirect(UserManager.GetUserMainPageWhenLoggedIn(SessionManager.LoggedUser.LanguageID,true));
}
else
{
Page.Response.Redirect(String.Format("~/{0}", Cultures.en.ToString()), true);
Helpers.SetCulture(Cultures.en.ToString());
}
}
I am using Response.Redirect to do that. Now if I set to End The Response the method parameter, it will throw an exception so I can handle it throught
try
{
this.InitializeLayout();
}
catch (ThreadAbortException ex)
{
}
catch (Exception ex)
{
ExceptionManager.LogException(ex);
}
If I don't end the Response, the page will execute the whole lifecyle, redirect and then do it again which results a double execution of the page. My main objective is not to execute the page 2 times to minimize processing ( if the site gets hammered by a big traffic). If I end the Response, a ThreadAbortExeption will be thrown and I think this is not good for the site.( I can catch it and not log it).
I have grid on my asp.net page. grid having 3 columns with hyper links. both links working properly. but one is not redirecting desired page. I tried in different browsers as well . but got different error : as
In Mozilla Firefox :The page isn't redirecting properly description In Mozilla Firefox :
Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies. In Google chrome : `This webpage has a redirect loop` description In Google chrome :
The webpage at http://myserver:425/(S(c0kr2xuftxiwhm25cm4vjg45))/mypage.aspx?type=2&userId=8 has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
since i tried lot of solutions over net , as i tried cleared cookies from browsers, added
<sessionState
cookieless="false" // True also tried
timeout="10">
</sessionState>
in web config file but problem is same there. I checked link is properly redirecting desired page. I mean i checked spelling of my link it is perfect. what else i have to try to resolve it ? where should i am making mistake ?
<ItemTemplate>
<a href="mypage.aspx?type=2&userId=<%#Eval("userId") %>">Go to my page </a>
</ItemTemplate>
I am using Forms Authentication in my VS-2005 website.In case of wrong credentials or while explicitly requesting protected pages the website is able to redirect user to login page. However, when correct login credentials are provided the application is not able to redirect the user to the desired page.While debugging I found that 'Request.IsAuthenticated=False' just before I redirect the user to the desired page.While coding I thought that this property will be set to true automatically after I generate the Authentication ticket. So do I need to set it explicitly inside the submit button click on Login page after validation?BTW I have not used the 'GetAuthcookie', 'SetAuthCookie' or 'RedirectFromLoginPage' methods.
I am posting the code inside the submit button click on the Login page as well as the Authentication and Authorization tags in web.config.
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="~/Login.aspx" cookieless="UseCookies" path="~/"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
Protected Sub btnsubmit_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
'here first validate if the user is valid user
ad = New Aranya_Data
[code]....
I originally have the question posted here, but I need as many eyes as possible on it.Essentially, I'm having issues redirecting to an action in mvc2 when working with JSON data. I post a stringified JSON object to an action and the action in turn redirects as needed. It worked previously when using form fields, but not when I'm posting JSON. To get posted JSON objects to properly bind to parameters objects in MVC, I'm taking advantage of the JsonValueProviderFactory class from MVC2Futures/MVC3Beta.Why is this occuring? The jQuery ajax call is telling the server "I'm giving you json, I expect html in return" and all actions pointed to via RedirectToAction calls are structured in a similar manner. I instead get stuck in a loop, continually hitting the originally requested action, with a prompt to reenter authorization information to boot! It seems lose authentication/authorization information in the process.The linked question on
View 4 RepliesI have created a custom error page to redirect whenever any error occurs. I made the following changes to the web.config file
<customErrors mode="On">
<error statusCode="403" redirect="~/Error.aspx" />
<error statusCode="404" redirect="~/Error.aspx" />
</customErrors>
Suppose my url is in the following way: http://MyTestSite/Posts/Post1.aspx
If I remove the .aspx at the end manually then it is not displaying my customm error page instead it is dispalying default 404 error page : Page cannot be found.
Also, if I give http://MyTestSite/Posts the same 404 error message is displaying. Even the Application_Error event in global.aspx is unable to handle this error.
How can I redirect these type of cases to my custom error Page? Do I need to make any changes in IIS default errors or can I able to acheive only using web.config?
i place the onClick event in asp buttons. but it is showing error like
Too many characters in character literal
my code is
<asp:Button ID="Button1" runat="server" Text="Button"
onClick="alert('The button was clicked.');" />
actually my requirement is when i click on the button i want to display some message and when we press ok then it is redirect to another page is it possible
I have a class...see code below
[Code]....
and I am calling the class using this syntax....
DataExporter.ExportToXLS(gvtemp,
string.Format("{0}.xls",
DateTime.Now.ToString("ddhhmmss")));
however, i am getting the exception, unable to evaluate expression because the code is optimized and usually, you fix it by adding a false to your response.redirect.
I am not able to redirect the user to "SimpleUserLoginAfterRegistration.aspx" page if Administrator is in any one of the .aspx file inside Administrator Folder.
I tried to use: Response.redirect("/SimpleUserLoginAfterRegistration.aspx") But, it is saying Page not found error.
i set anchor tag in masterpage as
<a onmouseout="mclosetime()" onmouseover="mopen('m2')" id="AnchorText5" href="#">TEst</a>
but when i run application and it render the page the anchor tag contain href address like
<a onmouseout="mclosetime()" onmouseover="mopen('m2')" id="ctl00_AnchorText5" href="../MasterPages/#">TEst</a>
i also try to set the "#" from code behind but it again show href="../masterpages/#"
What I am trying to achieve is to use an Eval as parameter in my anchor tag's href. The anchor is nested inside a repeater, why I cannot use the code behind to achieve this.
I have tried a few things without any luck.
<a href="http://MyWebsite/ActiveUsers?ID=InsertEvalHere"><%# Eval("Name")%></a>
The following code below is what I have tried to do:
<a href="<% "http://MyWebsite/ActiveUsers?ID=" + DataBinder.Eval(Container.DataItem("ID"))%>"><%# Eval("Name")%></a>
<a href="<% "http://MyWebsite/ActiveUsers?ID=" + Eval("ID")%>"><%# Eval("Name")%></a>
<a href="http://MyWebsite/ActiveUsers?ID=<% DataBinder.Eval(Container.DataItem("ID"))%>"><%# Eval("Name")%></a>
<a href="http://MyWebsite/ActiveUsers?ID=<%# Eval("ID")%>"><%# Eval("Name")%></a>
None of the above seemed to be right, as I keep getting this error - The tag is not well formed.
How should I handle this?
I've added this code below to a MOSS 2007 web part inside OnPreRender() method.
if (!Page.ClientScript.IsClientScriptBlockRegistered("jump_to_anchor_JS"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jump_to_anchor_JS", "window.location.hash="anchor";",true);
}
The page loads, jumps to the specific anchor, then jumps back to the top of the page. This has been tested in IE8, Firefox, Chrome, and Safari with same behavior.
I am using Web Forms Routing in ASP.NET 4 and I am trying to route to a specific location on a page. On that page I have an element like <div id="3"> and I'd like to jump to this anchor from another page. For this purpose I have defined a Route in global.asax:
RouteTable.Routes.MapPageRoute("MyRoute", "Path/SubPath/{PageAnchor}",
"~/MyPage.aspx", true, new RouteValueDictionary { { "PageAnchor", null } });
The HyperLink to link to that page and the anchor "3" is defined this way in markup:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="<%$ RouteUrl:RouteName=MyRoute,PageAnchor=#3 %>">
Link</asp:HyperLink>
The problem with the generated link is that the # character in the URL gets encoded by %23 this way: http://localhost:1234/Path/SubPath/%233 so that I reach the target page but not at the specified anchor.Is there a way to avoid this unwished URL-encoding? Or any other way to route to an anchor?
Given a web URL, I want to detect all the links in a WEBSITE, identify the internal links and list them.What I have is this:
WebClient webClient = null;
webClient = new WebClient();
string strUrl = "http://www.anysite.com";
[code]...
how to increment anchor tag id inside for loop.
View 4 RepliesI have a TabControl (Ajax Control Toolkit 1.0.10618.0) with 6 Tab Pages. On 1 Tab Page I have several internal anchors. I want to use URLs ike [URL]. This link opens Document ID 123 but it does not jump to Link2, probably because Link2 is on the 4th Tab page so it's not displayed initially. All these anchors only appear on the 4th tab but I could not set the 4th tab as general default tab because the 1st tab should be the default tab. When I manually open 4th and call the URL again then it's working fine. So I thought to inspect the Request.URL for '#Link' and , if found, switch to Tab4 automatically, but '#Link' does not appear anywhere in Request.URL.Is there a way to jump to an anchor on a currently not-opened tab?
View 6 Repliesi want to do this thing in c# code behind file.i want to check first wheather user click on it or not.if user click on that anchor tag then i want refresh div....
basically my div contain advertisements.every time when user click on anchor tag then new advertisements will be add in div..
I want to create a mailto anchor tag at runtime. Is this possible? I've tried this:
[Code]....
Neither of these worked. I tried adding the "mailto:" in front of the {0}, but this just became part of the perceived URL. I read a post online about using data attributes to add the value as a property of a class, but I can't do that, as I'm stuck using .NET 3.5 for this project. I honestly didn't think this was going to be such a big deal. I just want to populate the email address of the anchor tag with a variable value.
I noticed that the "disabled" property that appears in Intellisense for a link control doesn't work (when set to either True or False)..how can I programmatically accomplish the contextual disabling of a hyperlink via Visual Basic?
View 6 RepliesI have a link like this
<a href="#thumb" id="ctl00_allContent_btnThumb" onclick="javascript:__doPostBack('ctl00$allContent$btnThumb','')"><img alt="" src="../../images/bullet-thumb.gif"></a>
On Firefox it does what it supposed to. But it won't work on IE or Chrome.I know there are some questions on the subject here, but they haven't helped me. I'm guessing it's more specific since it envolves ASP.NET postback.
<a href="#testingPara">
<input type="button">
</a>
this code works
<a href="#testingPara">
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</a>
this doesn't workCan any one tell me the reason??
<a id="testingPara">
<p>Testing the anchor tags</p>
</a>
I am using a CSS button as
<a href="" class="btn green" title="Delete" OnServerClick="MyCodeBehindFunction">Delete </a>
Previously, I was using a button control instead of CSS button and using AJAX confirm extender before deleting. But how do I ask for this confirm action in < a href=""> now?
I have image button in my page i want when user click on image button it go to the bottom of the pageĀ
i know this codeĀ
1. The link which when clicked will goto bottom
<a href = "#bottom">Goto bottom</a>
2. The link to be placed at bottom of page
<a name = "bottom"></a>
but i have an imagebutton i want for imagebutton do that.
how i can do it?