I have Web-App. Somewhere in my page I used following code to create a Hyperlink.
<%= Eval("text") %>
as you see this code must be work but there is a little problem. content of NavigateUrl is something like this url.
"~/account/login.aspx"
How I must resolve that URL?
Update : I must say I cant Change value of NavigateUrl cuz that load from Xml-Datasource. I must change that in UI something like:
Eval( Resolveurl("NavigateUrl") )
You can try using Control.ResolveUrl.
Typically you would use Page.ResolveUrl to resolve a path relative to the current page, and this.ResolveUrl to resolve a path relative to the current control (UserControl or Page).
In your case, the tilde is relative to the application root, so either will do.
In response to your comment, you want to use something like:
ResolveUrl( (string)Eval("NavigateUrl"))
Related
I have Hyperlink in a datalist. HTML is given below:
<asp:HyperLink ID="lnkEntry" runat="server"><%# DataBinder.Eval(Container.DataItem, "Title") %></asp:HyperLink>
i have saved the URL of a Entry in the Database, like "http://test.com/posts/New-test-in-March" And used the following way to Bind it to Hyperlink in Item_databound of Datalist.
lnkEntry.NavigateUrl = objEntry.PermaLink;
But when it renders into the browser the URL get changed to "http%3a//test.com/posts/New-test-in-March"
i have tried to use the URLDecode but it doesn't make any change in output.
lnkEntry.NavigateUrl = Server.UrlDecode(objEntry.PermaLink);
Please help me how can i fix this issue.
you should use HttpUtility, like this:
lnkEntry.NavigateUrl = HttpUtility.UrlEncode(objEntry.PermaLink);
or WebUtility if running recent versions of .net.
Check this thread for more info.
I want my codebehind to dump a very large set of JS into the ASPX page. This is required, as I can't use external JS code for this component, and the code is also unique to each customer. Is it possible to do this from codebehind? I know how to set the value of text boxes etc. (.Text/.Value = xxx) but I can't see how I can just 'dump' code straight onto the page.
have a look at Page.ClientScripts.RegisterStartupScriptBlock or RegisterScriptBlock, these method do exactly what you need.
Try using RegisterClientScript:
http://www.codeproject.com/KB/aspnet/Register_Client_Script.aspx
set a string variable into code behind and then add to the page just
<%= variableName %>
where you want your js code to be dumped to
Or if you like you can create a method and do the same thing
<%= methodName() %>
I am using Server.Transfer() to transfer processing from one page to another. The problem is that the form action in the source of the page, having been transferred, refers to the destination page and not the original page as per the URL in the browser.
Is there a way to make the action of the form reflect the URL in the browser, rather than the actual destination page?
Thanks in advance!
Mark
Not to worry, I've rewritten my routing code using the System.Web.Routing namespace so all the logic is centralised in my global.asax. Works a treat!
Thanks for your help.
Mark
if you give the form an id you might be able to change the action in the attributes property.
<form runat="server" id="form1" action="">
</form>
and then in the code refer to the form like this:
form1.Attributes["action"] = "new action";
changing the action will probably cause postback events intended for the new page to work incorrectly. Your other alternative if your design permits would be to use the Response.Redirect.
Also, you might want to look into PostBackUrl for the buttons on the new page, which will change the page that they post to.
You should investigate if HttpContext.RewritePath might be useful here. Typically in cases like this you would use rewrite path on the PreRender event of the destination page using the URL of the original page. This causes controls that use the current internal path to generate URLs and such to "think" they are still on the original URL at the time they render themselves.
I have a label on a page which gets localized text through the meta:resourcekey attribute. The issue I have is that I want it to display different text depending on which view of a multiview they're on.
I tried adding the attribute though label.Attributes.Add("meta:resourcekey", "label"), but that doesn't seem to load any text. I tried it on PreRender, and same deal. The attribute appears when I look at the source, but no text is displayed.
Is this possible to do? The other option is to have 2 labels and change the visibility on page load, but that seems like the less elegant solution.
Thanks.
I think what you want for programmatic localisation in code behind is as simple as this:
ctrl.Text = (string)GetLocalResourceObject(“myCtrlKey.Text”);
ctrl.AnotherAttribute = (string)GetLocalResourceObject(“myCtrlKey.AnotherAttribute”);
Using LocalResource means that for a page called MyPage.aspx, you have created a resource file called MyPage.aspx.resx and/or MyPage.aspx.{culturename}.resx in the special directory App_LocalResource.
If you like Global Resources instead of local, use the special directory App_GlobalResource
to hold a resource file called MyResourceFileName.resx and call:
ctrl.Text= (string)GetGlobalResourceObject(“MyResourceFileName”, “myGlobalKey”);
copied from a blog about localization in the code behind
--
PS the reason that Attributes.Add("meta:resourcekey", "label") doesn't work is that "meta:resourcekey" isn't a real attribute and its use in the aspx is not really valid aspx markup - rather it's a preprocessing directive that causes the compiler to turn it into a longer list of attributes name/value pairs, based on what you've put in your resource file.
The approach of trying to assign a meta:resourcekey attribute will not work simply because they are treated specially by the page parser, and replaced before the page lifecycle code even really begins.
But meta:resourcekey is basically a declarative replacement for the code equivalent of accessing local resource files. In other words:
<asp:Label ID="MyLabel" meta:resource-key="MyResourceKey" />
is equivalent to:
<asp:Label ID="MyLabel" Text="<%$ Resources: myResXFile, MyResourceKey %>" />
is equivalent to the code:
MyLabel.Text = Resources.MyResXFile.MyResourceKey;
It looks like you're already dealing with your label in the code if you're trying to assign attributes to it. Why not set it's value in the code?
I created a hyperlink control extended from HyperLink, but I do not know how to override the navigateurl property, the problem is: im using a jquery library that depends on the url to look like this
#TB_inline?height=285&width=510&inlineId=contactUsContent
problem with .net is that it reorders this into:
../controls/?height=285&width=510&inlineId=contactUsContent#TB_inline
how can i force it to accept my string?
i think i was too hasty to ask this question, the simple solution was to decieve the hyperlink into making it an absolute url instead of relative, so all i had to do is insert a "/" at the beginning of the url
silly me!