Add LinkButtons during OnDayRender event of ASP.NET Calendar Control(在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkButtons)
问题描述
所以我需要根据数据库中的数据动态地为 asp:calendar 控件的每个单元格添加一些链接按钮.我想知道这样做的最佳方法是什么,以便链接按钮将在回发时连接到它们的事件(据我所知,在 Day Render 事件上创建链接按钮并将它们添加到 LinkButton 事件之后会发生被解雇了).
So I need to add some link buttons to each cell of a asp:calendar control dynamically based on data in the database. I wondering what the best way to do this is so that the the link buttons will be wired up to their events on postbacks (as to my knowledge creating the link buttons on the Day Render event and adding them there will occur after the LinkButton events would have fired).
有没有人有好的方法来处理这个问题?
Does anyone have a nice way to handle this?
推荐答案
这是一个 hack,但它有效,你必须巧妙地处理事件命名......等等
This is a hack but it works, you will have to get crafty with the event naming...etc
标记:
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
runat="server">
<asp:LinkButton ID="LinkButton1" style="display:none;" runat="server"
onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
代码隐藏:
protected void DayRender(Object source, DayRenderEventArgs e)
{
LinkButton lb = new LinkButton();
lb.ID = "LinkButton1";
//set all your props
lb.Attributes.Add("href",
"javascript:__doPostBack('" + Calendar1.UniqueID + "$" + lb.ClientID +"','')");
e.Cell.Controls.Add(lb);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//do something
}
这篇关于在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkButtons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkButtons


基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01