Click here to Skip to main content
15,917,456 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can we set a common default events for the list of similar web controls which are used for the same operations but resulted in a uniquely identified controls

please help me
Posted
Comments
phil.o 27-Oct-11 4:11am    
Your question isn't clear at all. Could you be more descriptive/specific ?
sandhya.T 2011 27-Oct-11 4:23am    
here im having a list of controls of list of persons
the info of these are similar properties as name, age, address like that
in every individual web control can set to the common event as
ddl_SeletedChanged().
For every person details instead of going to write the individual events can we go for the common event

If all your controls are of type DropDowList, you just have to create your event handler, which must have the correct signature for the DropDownList.SelectedItemChanged.
Just assign this event handler to all of your DropDownLists.

The first parameter of the event handler is of type object ; it refers to the control that has raised the event. In your event handler, just cast this object to a variable of type DropDownList, and then go with your logic from there.

Example :

private void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
   DropDownList ddl = (DropDownList)sender;
   // Go on with your logic, using ddl variable just created
}


This way all your DropDownLists SelectedIndexChanged events will be handled by the same event handler.

Hope this helps.
 
Share this answer
 
Comments
sandhya.T 2011 27-Oct-11 5:17am    
thanq
but where should i place the code
i.e Webform.aspx.cs
or in the class1.cs(used to create the table with the all controls)
In above these two files where can place the events.
phil.o 27-Oct-11 5:28am    
Place it where you are creating your DropDownLists.
sandhya.T 2011 27-Oct-11 6:21am    
actually
i have created these web controls with in the scope of switch cases
which in the class1.cs file
so can i place them with in the switch case itself or with the scope of class
sandhya.T 2011 27-Oct-11 5:24am    
In the above code how can i get the value of the passed ddl.SelectedItem.Value property
i.e
Response.WriteLine("" +ddl.SelectedItem.Value.ToString());
phil.o 27-Oct-11 5:27am    
I don't get your question. The code you provide is showing that you already know how to access the Value property.
Hi,

you can handle all events which are raised from common type of controls

Here I'm giving some idea how to handle multiple control events in single handler

ASP.NET
 <table width="300"><tr>
  <td>
      <asp:linkbutton id="LinkButton2" runat="server" commandargument="First" onclick="LinkButton2_Click" xmlns:asp="#unknown">First</asp:linkbutton></td>
  <td>
      <asp:linkbutton id="LinkButton3" runat="server" commandargument="Prev" onclick="LinkButton2_Click" xmlns:asp="#unknown">Prev</asp:linkbutton></td>
  <td valign="bottom">
</td></tr></table>


Like in the above code i've too many linkbuttons in my webcontrol
I can handle all events in my single handler like if any linke clicks
it can raise only LinkButton2_Click event

And in my single I write code for all linkbutton features
C#
protected void LinkButton2_Click(object sender, EventArgs e)
  {
      if (((LinkButton)sender).CommandArgument.ToString() == "First")
      {
          ReqPageNo = "1";
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Prev")
      {
          if (int.Parse(crntpage.Value) == 1)
          {
              ReqPageNo = "1";
          }
          else
          {
              ReqPageNo = (int.Parse(crntpage.Value) - 1).ToString();
          }
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Next")
      {
          if (int.Parse(crntpage.Value) == int.Parse (TotalPageNo))
          {
              ReqPageNo = TotalPageNo;
          }
          else
          {
              ReqPageNo = (int.Parse(crntpage.Value) + 1).ToString();
          }
      }
      if (((LinkButton)sender).CommandArgument.ToString() == "Last")
      {
          ReqPageNo = TotalPageNo;
      }
      Click(this, e);
  }


Like this you can handle any event in single handler

I hope you understood what I said

All the Best
 
Share this answer
 

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