-1

我是编程新手,但我会先展示代码,然后解释我想做什么

private void ModalBody()
{
    LoadTemplateOverride();
    divModalBody.InnerHtml = 
}
private void LoadTemplateOverride()
{
    string templateURL = String.Format("{0}/leadgen/eodemails/templatecontroller.aspx?eodid={1}", site.Get("InternalApiUrl"), Email.ID);
    HttpWebRequest request = HttpWebRequest.Create(templateURL) as HttpWebRequest;

    HttpWebResponse response = request.GetResponse() as HttpWebResponse;

    tbSubject.Text = response.Headers["EmailSubject"];
    tbBody.Text = (new StreamReader(response.GetResponseStream())).ReadToEnd();
}

所以我想要做的是将“LoadTemplateOverride”调用到 ModalBody,然后divModalBody.InnerHtml =从 ModalBody(new StreamReader(response.GetResponseStream())).ReadToEnd();与 LoadTemplateOverride 相等。但是每当我这样做时,它都无法识别“响应”...

4

1 回答 1

2

我对您要做什么感到非常困惑,但是一个问题很清楚,那就是您似乎没有意识到您试图从 ModalBody 调用的 LoadTemplateOverride() 中的“响应”实例() 对它所在的方法是私有的,并且对 ModalBody() 是不可访问的。

不仅如此,一旦 LoadTemplateOverride() 完成执行,其中声明的对象不再存在于任何实际目的。如果您尝试将 divModalBody.InnerHtml 的值设置为在 LoadTemplateOverride() 执行时出现的响应实例的值,那么我建议您让 LoadTemplateOverride() 不返回 void,而是返回 HttpWebsponse。然后您对 LoadTemplateOverride() 的调用可以与将 divModalBody.InnerHtml 的值设置为它返回的值相结合。例如:

private void ModalBody()
{
    divModalBody.InnerHtml = LoadTemplateOverride();
}
private HttpWebResponse LoadTemplateOverride()
{
    string templateURL = String.Format("{0}/leadgen/eodemails/templatecontroller.aspx?eodid={1}", site.Get("InternalApiUrl"), Email.ID);
    HttpWebRequest request = HttpWebRequest.Create(templateURL) as HttpWebRequest;

    HttpWebResponse response = request.GetResponse() as HttpWebResponse;

    tbSubject.Text = response.Headers["EmailSubject"];
    tbBody.Text = (new StreamReader(response.GetResponseStream())).ReadToEnd();

    return response;
}
于 2013-06-07T18:37:11.847 回答