Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)

C#
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)
        {
            
        }


this Serverclick function is not calling.i think this anchor is lost on postback.I dnot know much abt this.
Posted
Updated 10-Sep-12 22:49pm
v3
Comments
Sandeep Mewara 11-Sep-12 3:47am    
It would help if we see your implementation - we will able to suggest/comment on what and why.

Please use 'Improve Question' link to edit/update question.
AmitGajjar 11-Sep-12 3:55am    
code please ?
Mohamed Mitwalli 11-Sep-12 4:55am    

Hi ,
check this
C#
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>");
}

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

Best Regards
M.Mitwalli
 
Share this answer
 
v2
Look for a tag.
So while adding anchor tag set its onserverclick property to you server dide function.
C#
<a id="id"  runat="server"  önserverclick="serverfunction">click</a>


C#
protected void serverfunction(object sender, EventArgs e)
       {
//You implementation
       }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900