2013-04-19 14 views
6

próbuję wysłać wiadomość e-mail za pośrednictwem WebMethod Poniżej znajduje się kod I zazwyczaj korzystają regularnie post PowrótLoadControl, usercontrol w WebMethod

[WebMethod] 
public static void SendEmail(string name, string phone, string emailaddress, string interest, string comments) 
{ 
    var control = LoadControl("~/Shared/Controls/EmailTemplate_PartnerWithUs.ascx"); 

    StringBuilder sb = new StringBuilder(); 
    StringWriter sw = new StringWriter(sb); 
    Html32TextWriter htw = new Html32TextWriter(sw); 

    control.RenderControl(htw); 

    sb.Replace("%name%", name); 
    sb.Replace("%phone%", phone); 
    sb.Replace("%emailaddress%", emailaddress); 
    sb.Replace("%interest%", interest); 
    sb.Replace("%comments%", comments); 
    EmailUtility.SendEmailMessage(SettingsManager.GetContactRecipientEmails(), "CoyleHomeBuyers.com Partner Form", sb.ToString()); 
} 

Błąd Dostaję jest:

An object reference is required for the non-static field, method, or property 'System.Web.UI.TemplateControl.LoadControl(string)' 

Czy istnieje sposób załadowania tego formantu w narzędziu WebMethod?

Odpowiedz

6
UserControl uc= new UserControl(); 
Control control = uc.LoadControl("~/Shared/Controls/EmailTemplate_PartnerWithUs.ascx"); 
+0

doskonały, zrobiłem to już wcześniej, ale nie mógł go znaleźć, wiedział, że to całkiem proste. –