ASP.NET日历控件OnDayRender事件过程中添加LinkBut​​tons [英] Add LinkButtons during OnDayRender event of ASP.NET Calendar Control

查看:454
本文介绍了ASP.NET日历控件OnDayRender事件过程中添加LinkBut​​tons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我需要一些链接按钮添加到ASP的每个单元:动态地根据数据库中的数据日历控件。我想做到这一点的最好办法是什么,这样的链接按钮将有线到他们的活动上回发(因为据我所知,创造当日链接按钮渲染事件并加入他们的LinkBut​​ton事件发生后会有出现会已经解雇了)。

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?

推荐答案

编辑:这是一个黑客,但它的工作原理,你将获得狡猾与事件命名...等

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>

code-背后:

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事件过程中添加LinkBut​​tons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆