动态创建HTML锚并在内容页面上附加事件 [英] dynamically create Html anchor and attach event on it in content page

查看:89
本文介绍了动态创建HTML锚并在内容页面上附加事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在内容页面的PostBack函数上创建Htmlanchor.M还将事件onclick或Serverclick附加到Html锚点.但是该事件没有触发.
请对此进行帮助.


通过内容页面在母版页上创建HTMLAnchor

在内容"页面上(在gridview Item命令中)

Hi,

Creating Htmlanchor on PostBack function in content page.M also attaching event onclick or Serverclick to Html anchor.But that event is not firing.
Plz help on this.


create HTMLAnchor on Master page through content page

on Content page (in gridview Item command)

CMS.Web.MasterPages.CMSMaster mstr = (CMS.Web.MasterPages.CMSMaster)Page.Master;
UpdatePanel up = (UpdatePanel)mstr.FindControl("updtBreadcrumb");    
 HtmlAnchor htmlanchorpool = new HtmlAnchor();
                            htmlanchorpool.ID = "anchorid";
                            htmlanchorpool.Title = Module.Pool;
                            htmlanchorpool.InnerText = Module.Pool;
                            htmlanchorpool.HRef = "#";
                            htmlanchorpool.ServerClick += new EventHandler(htmlanchorpool_ServerClick);

                            up.ContentTemplateContainer.Controls.Add(htmlanchorpool);    


protected void htmlanchorpool_ServerClick(object sender, EventArgs e)
        {
            
        }



此Serverclick函数未调用.我认为此锚在回发时丢失.我对此不甚了解.



this Serverclick function is not calling.i think this anchor is lost on postback.I dnot know much abt this.

推荐答案


检查此
Hi ,
check this
protected void Page_Load(object sender, EventArgs e)
{
    System.Web.UI.HtmlControls.HtmlAnchor anchor1 = new System.Web.UI.HtmlControls.HtmlAnchor();
    anchor1.InnerText = "Click Here";
    anchor1.ServerClick += new EventHandler(anchor1_Click);
    form1.Controls.Add(anchor1);
}
protected void anchor1_Click(object sender, EventArgs e)
{
    Response.Write("<script>alert('hello')</script>");
}


您也可以检查此链接
不触发动态创建按钮的单击事件 [ ^ ]

最好的问候
M.Mitwalli


You Can check this link too
not firing dynamically cretated button click event[^]

Best Regards
M.Mitwalli


寻找标签.
因此,在添加锚标记时,将其onserverclick属性设置为服务器dide函数.
Look for a tag.
So while adding anchor tag set its onserverclick property to you server dide function.
<a id="id"  runat="server"  önserverclick="serverfunction">click</a>





protected void serverfunction(object sender, EventArgs e)
       {
//You implementation
       }


这篇关于动态创建HTML锚并在内容页面上附加事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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