Search code examples
c#master-pages

Problem with static string in Master Page on c#


I have added in Master Page in C# the following static string :

public static string GetHtmlPage(string strURL)
{
    String strResult;
    WebResponse objResponse;
    WebRequest objRequest = HttpWebRequest.Create(strURL);
    objResponse = objRequest.GetResponse();
    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
    {
        strResult = sr.ReadToEnd();
        sr.Close();
    }
    return strResult;
}

Now I need use the following static string on code-behind of .cs page with Master Page like below :

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        string TheUrl = "http://...";
        ((Mp)Master).GetHtmlPage(TheUrl);
    }
}

But I have error :

Member cannot be accessed with an instance reference qualify it with a type name instead static method

How to do fix it ?


Solution

  • You can't access the static methods via class instance, instead you must use the type strictly like below:

    Mp.GetHtmlPage(TheUrl);