Same event for both template control

Last post 07-05-2009 12:24 PM by alessandro. 5 replies.

Sort Posts:

  • Same event for both template control

    07-05-2009, 9:53 AM
    • Member
      5 point Member
    • Yaniv.net
    • Member since 07-04-2009, 1:31 PM
    • Posts 59

     Hi,

    i have  a listview, in both Insert Template and Update Template i have the same drop downlist, i would like to create event for SelectedIndexChanged for this DropDownList,

    i want that these two controls will use the same event function, but i would like to identify which one of the control call the event, how can i do that ?

     

    Thanks.

  • Re: Same event for both template control

    07-05-2009, 10:34 AM
    • All-Star
      89,388 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,299
    • Moderator
      TrustedFriends-MVPs
        protected void CommonSelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList Source = sender as DropDownList;
    
            if (Source.ID == "DropDownList1")
                Response.Write("DropDownList1");
            else if (Source.ID == "DropDownList2")
                Response.Write("DropDownList2");
            else
                Response.Write("Bad sender");
        }


     

    Steve Wellens

    My blog
  • Re: Same event for both template control

    07-05-2009, 10:50 AM
    • Member
      5 point Member
    • Yaniv.net
    • Member since 07-04-2009, 1:31 PM
    • Posts 59

    Thanks, but the both have the same name...

    i would like to indentify from who is the source template of the dropdownlist, was it the insert template or the update template.

     

    Thanks 

  • Re: Same event for both template control

    07-05-2009, 11:12 AM
    Answer
    • All-Star
      89,388 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,299
    • Moderator
      TrustedFriends-MVPs

     You can check the parent of the DropDown  (you may have to cast it)

     

            DropDownList Source = sender as DropDownList;

            if (Source.Parent == ...

    Steve Wellens

    My blog
  • Re: Same event for both template control

    07-05-2009, 11:26 AM
    • Member
      5 point Member
    • Yaniv.net
    • Member since 07-04-2009, 1:31 PM
    • Posts 59

    Sorry but i do not understand,

    what should i cast ? the parent control ? to which control shold i cast it ?

    i just want to know who is the template who fired the event,

     

    Thanks

  • Re: Same event for both template control

    07-05-2009, 12:24 PM
    Answer
    • Contributor
      6,788 point Contributor
    • alessandro
    • Member since 06-25-2002, 10:05 AM
    • Italy
    • Posts 1,103

    The previous poster is correct. That is practically the only other option left to you at this point :


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;
            ListViewItem lvi = (ListViewItem)ddl.NamingContainer;
            if (lvi.ItemType == ListViewItemType.InsertItem)
            {
                //in insert template
            }
        }

    Alessandro Zifiglio
    www.jiffycms.net - opensource HTML Editor for ASP.NET
    http://weblogs.asp.net/alessandro


    In the land of the blind, the man with one eye is king!:x
Page 1 of 1 (6 items)