Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharepoint - Custom Field - ImageButton - Onclick event

Status
Not open for further replies.

zerabba

Programmer
Jan 29, 2010
1
CH
Helllo,

I created a custom field which is a multiple lookup filed. It shows the binded data and under there is a form to add a new data. My problem is with the Button to delete each item in the list. I show you the code and put some comments to explain the problem:

Code:
public class ListSubFormControl : MultipleLookupField 
{ 
 
  // The field containing the IDs of the lookup field 
  public override object Value 
  { 
    set 
    { 
      EnsureChildControls(); 
      SPFieldLookupValueCollection lookupValues = value as SPFieldLookupValueCollection; 
 
      if (lookupValues != null)  
      { 
        foreach (SPFieldLookupValue fieldValue in lookupValues) 
        { 
          // I fill a lookup list with the IDs 
          lookupList.Items.Add(new ListItem(fieldValue.LookupValue,fieldValue.LookupId.ToString())); 
        } 
      } 
    } 
  } 
 
  // The method called to create the list of all binded data 
  public void ShowSubFormList() 
  { 
 
    foreach (ListItem item in lookupList.Items) 
    { 
      /* ...  other code not showed here ... */                     
 
      // We create a delete button for each binded data 
      ImageButton delItem = new ImageButton(); 
      delItem.ImageUrl = "/_layouts/images/delete.gif"; 
      delItem.Click += new ImageClickEventHandler(delItem_Click); 
      oCellLabel = new TableCell(); 
      oCellLabel.CssClass = "ms-formbody"; 
      rowItem.Cells.Add(oCellLabel); 
       oCellLabel.Controls.Add(delItem); 
    } 
  } 
 
  void delItem_Click(object sender, ShowSubFormList(), e) 
  { 
     // the code to delete the item 
   } 
 
  protected override void CreateChildControls() 
  { 
    // If I call the ShowSubFormList(), the value isn't set and the list will be empty 
  } 
 
  protected override void OnLoad(EventArgs e) 
  { 
    // If I call the ShowSubFormList() here, it's working but after a delItem_Click, the deleted item will be still in the list...  
  } 
 
  protected ovverride void OnPreRender(EventArgs e) 
  { 
     // If I call the ShowSubFormList() here, the list is the right list (I also have a button to add a new item and after an insert, it's the correct list), put the delete ImageButton no more working -> the event on the Click() never called... 
  } 
}

Where should I put the ShowSubFormList() method so that it works after a refresh and the Event works too?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top