Unable to access ASP.NET Page inside a folder - asp.net

I am using ASP.NET/C#.
In my menu I have this li item
<li>Update Deposit Interest</li>
But when I try to click on the a tag it just gives me this error
Cannot use a leading .. to exit above the top directory.
Can anyone just point me as to what might be missing here?
Any suggestions are welcome.

The problem could be caused by the DepositInterest.aspx page that you are navigating to. Are there any javascript/CSS files liked on that page or in the master page? If so you might want to check out that they are linked correctly.
Cannot use a leading .. to exit above the top directory
http://forums.asp.net/t/1019849.aspx

link should starts with tilde which represent root of your site or mention your complete address
<li><a href="~/Deposits/DepositsInterest.aspx" runat="server" >Update Deposit Interest</a></li>
// or type complete address
<li>Update Deposit Interest</li>
// or use asp.net hyperlink
<li> <asp:HyperLink id="hl1"
NavigateUrl="~/Deposits/DepositsInterest.aspx"
Text="Hyperlink"
Target="_new"
runat="server"/> </li>
Updated answer:
If you are adding hyperlinks dynamically then add them as:
MenuItem mi = new MenuItem();
mi.NavigateUrl = "~/Deposits/DepositsInterest.aspx";
mi.Text = "MY hyperlink";
Menu1.Items.Add(mi);
Menu1.DataBind();

Related

How to change javascript:__doPostBack Url to full Url

I'm an SEO by profession and I have recently developed a database driven ASP.NET site. I have a problem with my website's internal linking. My links are shown as doPostBack, but I want them to display the actual URL so that search engines can crawl them.
Current: This is link pattern in my sidebar. All links are in this format
<ul>
<li><a id="linkHome" href="javascript:__doPostBack('ctl00$linkHome& #39;,'&#39">Home</a></li>
This is just one link from the sidebar. All links are in this format. I want them to be like
<li><a id="linkHome" href="http://www.example.com">Home</a></li>
How can I make this happen?
Tell your developer to use normal href links for those if they're links instead of asp:LinkButton which is what he's using I think. Alternatively move to MVC and use the MVC router. He's using server side controls for what (you're telling me) can be client side links (standard anchor tags) The asp:LinkButton causes server side processing just to handle a link which is silly if the pages can be reached directly with no need to make a server request.
edit:
For a little more detail, here's what your developer is probably doing, either:
<asp:LinkButon runat="server" id="linkHome" OnClick="linkHome_OnClick" Text="Home" />
or maybe
<asp:HyperLink runat="server" id="linkHome" NavigateUrl="example.com" Text="Home" />
what he should do is simply:
Home

use asp:LinkButton in umbraco

im creating a umbraco plugin, which uses an asp:LinkButton. which looks something like this
<asp:LinkButton ID="ObjectInformationBtn" class="link" runat="server" Text="View Full Details of Item" OnClick="ObjectInformationBtn_Click"></asp:LinkButton>
when I test this plugin locally I get the following result
View Full Details of Item
however when I put the plugin on the website I get a complete different results, which looks like this
<p> </p>
can someone please tell me what is going on.
Are you sure the ascx containing the linkbutton is published to the production website in the usercontrols folder?
Do you have a Macro created that references the User Control that contains the LinkButton?

How to avoid Adding runat="server" destroying my server tags <%...%>

Adding runat="server" is not rendering my server tags <%...%>
I have a masterpage with a few <li> for menu and since I have to set class=selected for the current page, I am using a little server tag to find the url and assign the particular class.
I have total of 10 <li> and not all menu is available to all types of user, I need to toggle few of the <li> if the user is not admin, so I have runat="server" added to them so I can set their visible=false through c#
Here is how it is at a glance:
<li runat="server" id="liBlog" class='<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>'>Group Blog</li>
<li runat="server" id="liPoll" class='<%= Request.Url.AbsoluteUri.EndsWith("/Poll") ? "selected" : "" %>'>Poll</li>
<li id="liInvite" class='<%= Request.Url.AbsoluteUri.EndsWith("/Invite") ? "selected" : "" %>'>Invite</li>
<li id="liFavourite" class='<%= Request.Url.AbsoluteUri.Contains("/Favourite") ? "selected" : "" %>'>My Favourites</li>
The <li> without runat="server" works fine, when on correct page the source code shows class="selected" or class="" as appropriate, the other <li> used to work fine too, until I decided to add the runat="server".
Once I added that runat="server", the whole block of class="" is being sent out to the html page, its not processing the server tags at all! I right click on the html and look at the source, it's being rendered as:
<li id="ctl00_ctl00_ContentPlaceHolder1_liBlog" class="<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>">Group Blog</li>
It's pouring out my server tags into the source code!
Why is this behaviour seen? How can I avoid it?
I looked up a lot of similar threads in here and there was nearly nothing in google, so made this, I dont think this is a duplicate question.
You can't use the <%= %> syntax inside the properties of tags that have the runat="server" attribute on them.
You either need to:
Set the properties via your code-behind
Create an Expression Builder (and part 2 and part 3) and use the <%$ %> syntax (note: these are links to stuff I wrote on my blog, so, beware the self link =)
for your requirement you can also use ASP.NET menu and XmlSiteMap to do the same thing.

How to WelCome control in Webpart code?

I need to place a webpart on the page. The webpart need to change Welcome control title. I need to change "WelCome UserName" to "UserName".
I tried http://www.wictorwilen.se/Post/Having-fun-with-the-SharePoint-Welcomeascx-control.aspx , But it did not worked in Webpart. If anybody have idea to change this control. Please share with me.
That article is a pretty comprehensive walkthrough of one way to do this - perhaps your focus should be to determine where you have gone wrong in the implementation of it?
An alternative (hacky) method would be to put some javscript into the page using a CEWP or modifying the master page that will search for the welcome string and remove it.
Hint - don't search for "Welcome", search for its container which looks a little like this (some attributes stripped out for clarity
<span title="Open Menu">
<div id="zz7_Menu_t" ...
class="ms-SPLink ms-SpLinkButtonInActive" >
<a accesskey="L" id="zz7_Menu" ... href="#" serverclientid="zz7_Menu"
menutokenvalues="MENUCLIENTID=zz7_Menu,
TEMPLATECLIENTID=zz3_ID_PersonalActionMenu">
Welcome UserName
</a>
</div>
</span>
Some links to get you started
http://www.dlocc.com/articles/style-a-page-using-the-content-editor-web-part-and-css/
http://www.cleverworkarounds.com/2008/02/28/more-sharepoint-branding-customisation-using-javascript-part-2/
http://blog.pathtosharepoint.com/2008/08/10/the-content-editor-web-part/

Literal used for variable css

I'm using literal to implement css, so as to have the css class vary depending on the page I'm on, the css being applied to some "a" tags also.
That bit (variable css on a tags) seems to be working for me at present for some reason, but the code breaks the use of the ~/ within links...
Does anyone know if there any consequences of using the below but limiting my pages to the root folder - as it does seem to be working there at least:
<li>
<a <asp:Literal id="ClassToUse" runat="server"/> id="home_link"
href= "Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a>
</li>
Or if it is possible to get the path from root (~/) working within it, so as to enable a better folder layout/hierarchy.
I don't have an Openid and have given up on trying to sign in - for a while.
A few alternatives come to my mind:
Use a <asp:Hyperlink> and set CssClass property of the hyperlink instead of setting the value of the ClassToUse literal.
Fix the CSS class name of the link but change the CSS definitions by putting the <style> section on your page into a changeable literal.
But it's also possible that I misunderstood your question...
Thanks for the help Heinzi - this one got both working together for me... Went "You beauty" when it worked :)
<li><asp:Hyperlink id="ClassToUse" runat="server" NavigateUrl="~/Default.aspx" title="Home" onfocus="this.blur();">Home</asp:Hyperlink></li>
Case "Default.aspx"
' switch the background pics for the li
ClassToUse.CssClass = "active"

Resources