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 服务器控件
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
