How to use ASP.Net server controls inside of Substitution control?(如何在 Substitution 控件中使用 ASP.Net 服务器控件?)
问题描述
虽然我们在 Substitution 控件中使用的方法应该返回字符串,那么如何使用 应该在服务器端呈现吗?
例如登录视图控件?
while the method we use in Substitution control should return strings, so how is it possible to use a donut caching in web forms on a server control which should be rendered server side?
for example Loginview control?
推荐答案
UPDATE现在这是一个完整的示例.这里发生了一些事情:
UPDATE This is now a fully working example. There a few things happening here:
- 使用替代控件的回调来呈现您需要的用户控件的输出.
- 使用覆盖 VerifyRenderingInServerForm 和 EnableEventValidation 的自定义页面类来加载控件,以防止在用户控件包含需要表单标记或事件验证的服务器控件时引发错误.
这是标记:
<asp:Substitution runat="server" methodname="GetCustomersByCountry" />
这是回调
public string GetCustomersByCountry(string country)
{
CustomerCollection customers = DataContext.GetCustomersByCountry(country);
if (customers.Count > 0)
//RenderView returns the rendered HTML in the context of the callback
return ViewManager.RenderView("customers.ascx", customers);
else
return ViewManager.RenderView("nocustomersfound.ascx");
}
这里是呈现用户控件的辅助类
public class ViewManager
{
private class PageForRenderingUserControl : Page
{
public override void VerifyRenderingInServerForm(Control control)
{ /* Do nothing */ }
public override bool EnableEventValidation
{
get { return false; }
set { /* Do nothing *
本文标题为:如何在 Substitution 控件中使用 ASP.Net 服务器控件
基础教程推荐
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
