Al Lelopath
Al Lelopath

Reputation: 6778

Refer to key-value in ascx

I have a key-value pair defined in the Web.Release.config and Web.Debug.config for a url. In the C# file I use it like so (key is "Report-URL"):

string reportUrl = System.Configuration.ConfigurationManager.AppSettings["Report-URL"];
CoverSheetReportViewer.ServerReport.ReportServerUrl = new Uri(reportUrl);

This works but now I want to use it in a .ascx file where I currently have the url hardcoded:

<asp:HyperLink ID="HyperLinkReports" runat="server" CssClass="LeftNav" 
NavigateUrl="http://mygroup-dev-appsr/ReportServer?%2fASD%2fTransactions%2fCoverSheet&rs:Command=ListChildren" />

How do I do this?

Upvotes: 1

Views: 362

Answers (1)

Murali Murugesan
Murali Murugesan

Reputation: 22619

Try this with help of Inline Syntax

NavigateUrl="<%$ AppSettings:Report-URL %>

or

In .ascx

<a href="<%# this.GetReportUrl() %>">Report</a>

in .ascx.cs

protected string GetReportUrl(){
 string reportUrl = System.Configuration.ConfigurationManager
                   .AppSettings["Report-URL"]; 

 return  new Uri(reportUrl).ToString();
}

Another Syntax Reference

Upvotes: 3

Related Questions