内部类ASP.Net C#ResolveClientUrl [英] ASP.Net C# ResolveClientUrl inside Class

查看:214
本文介绍了内部类ASP.Net C#ResolveClientUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

public class NavigationPath
{
    private string menuItems = "<li>" +
                                    "<a href=\"#\">home</a>" +
                               "</li>";

不过,我想有:

public class NavigationPath
{
    private string menuItems = "<li>" +
                                    "<a href=\"" + ResolveClientUrl("~/home.aspx") + "\">re</a>" +
                               "</li>";

不过,我不能够使用ResolveClientUrl一类中。任何ideias?

However, I am not able to use ResolveClientUrl inside a Class. Any ideias?

提前THX,对于u'r恬。

Thx in advance, for u'r tim.

推荐答案

ResolveClientUrl是System.Web.UI.Control类的成员,因此它直接访问为:

ResolveClientUrl is a member of the System.Web.UI.Control class, hence it's accessible directly as:

var url = ResolveClientUrl("~/Some/Url/");

当您的asp.net页面的code中调用。

when called within the code of your asp.net page.

要使用它你将不得不页面(或页面上的控件)传递到在其构造函数类的类中。即使如此,我不知道你能在你指定的方式来使用它。你可能不得不做类似的东西:

To use it inside a class you're going to have to pass the Page (or a control on the page) into the class in its constructor. Even then I'm not sure you'd be able to use it in the way you've indicated. You'd probably have to do something similar to:

public class NavigationPath
{
  private string menuItems = string.Empty;

  public NavigationPath(Page page)
  {
    menuItems = "<li>" + "<a href=\"" + page.ResolveClientUrl("~/Home.aspx") + "\">home</a>" + "</li>";
  }
}

和那么你的asp.net页面中做这样的事情:

And then inside your asp.net page do something like:

var navPath = new NavigationPage(this);

这篇关于内部类ASP.Net C#ResolveClientUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆