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


- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 使用 rss + c# 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01