Set Dropdown's OnSelectedIndexChanged method On The Fly

At work, I came across a situation where I had to set a dropdown's OnSelectedIndexChanged method programmatically.

Here's how to do it:
dropdowndRoleList.AutoPostBack = true;
dropdownRoleList.Attributes["OnSelectedIndexChanged"] = "RoleType_Changed";

Where RoleType_Changed is a C# method:

public void RoleType_Changed(object Sender, EventArgs e)
{
        ResetErrorMessage();

         if (rdoList.SelectedValue == RoleTypeData.ROLETYPE.BASC.ToString())
         {
            ddRoleList.AutoPostBack = true;
            ddRoleList.Attributes["OnSelectedIndexChanged"] = "RoleType_Changed";
         }
         else
         {
            ddRoleList.AutoPostBack = false;
         }
}
 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name (required)

 Email (will not be published) (required)

Your comment is 0 characters limited to 3000 characters.