Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Can't get click event to load from ImageButton

$
0
0

*Newbie Alert*

I am trying to create dynamic image buttons that when clicked will redirect to anothr page as well as add a new item to a SharePoint list. My Image buttons create sucessfully but the click event is not loaded. I have added a break point visual studio and can see that the function is never loaded.

My Image button creation code (within Page_load) is:

                   ImageButton lnk = new ImageButton();
                   lnk.ID = WPtitle;
                   lnk.CommandName = WPtitle;
                   lnk.CommandArgument = WPtitle;
                   lnk.PostBackUrl = WPUrl;
                   lnk.Visible = true;
                   lnk.ImageUrl = WPImgUrl;
                   tc.Controls.Add(lnk);
                   lnk.Click += new System.Web.UI.ImageClickEventHandler(this.send_Click);

and then my event is:

public void send_Click(object sender, ImageClickEventArgs e)
        {
            SPWeb site = SPContext.Current.Web;
              var clicklist = site.Lists["listname"];
              string WPTitle = ((ImageButton)sender).CommandArgument.ToString();
                SPListItem additem =  clicklist.AddItem();
                additem["Title"] = "text";
            additem["Clicked"] = "1";
                additem.Update();

Any help as to why this is not loading would be greatly appreciated.

Thanks


Viewing all articles
Browse latest Browse all 11571

Trending Articles