从 Windows 应用程序加载控件
是否可以在Windows应用程序中LoadControl?
我有网络电子邮件生成功能,但我想将其移动到 Windows 服务以获取每月通讯。
电子邮件现在被实现为用户控件,通过这种方式,html 人员可以轻松修改外观和内容。感觉。
当前的渲染实现如下所示:
StringBuilder sb = new StringBuilder(4000);
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
EmailTemplateBase emailCtrl = (EmailTemplateBase)page.LoadControl(
"Controls/EmailTempaltes/Template.ascx");
// Exception here
emailCtrl.DataContext = dataContext;
emailCtrl.Parameter = parameter;
emailCtrl.RenderMode = renderMode;
emailCtrl.DataBind();
emailCtrl.RenderControl(htw);
subject = emailCtrl.Subject;
string MessageText = sb.ToString().Replace("\t", "").Replace(Environment.NewLine, "");
return MessageText;
Is it possible to LoadControl in windows application?
I have email generation as web, but I want to move it to windows service for monthly newsletter.
Emails now are implemented as UserControls, in this way html person can easily modify look & feel.
Current rendering implementation looks like:
StringBuilder sb = new StringBuilder(4000);
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
EmailTemplateBase emailCtrl = (EmailTemplateBase)page.LoadControl(
"Controls/EmailTempaltes/Template.ascx");
// Exception here
emailCtrl.DataContext = dataContext;
emailCtrl.Parameter = parameter;
emailCtrl.RenderMode = renderMode;
emailCtrl.DataBind();
emailCtrl.RenderControl(htw);
subject = emailCtrl.Subject;
string MessageText = sb.ToString().Replace("\t", "").Replace(Environment.NewLine, "");
return MessageText;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的解决方案是调用 Web 服务,它能够从 .ascx 生成 Html。
Webservice中的webservice
new Page,然后将LoadControl
字符串生成器。
您可以看到有问题的代码。
Solution for me was to call web service, which was able to generate Html from .ascx.
webservice
new Page, than LoadControl
StringBuilder.
You can see code in question.
您可以使用父控件的
Controls.Add
方法,而不是asp.net 中使用的LoadControl
方法。只需添加一个面板作为父面板即可:instead of the
LoadControl
method used in asp.net, you can useControls.Add
method of the parent control. Just add a panel to be the parent then: