Last post Apr 22, 2011 10:29 PM by jkirkerx
Apr 20, 2011 03:01 AM|joydeep1985|LINK
hii i have created a class which inherits the properties of System.Web.UI.WebControls.DropDownList.
now the problem is when i set autopostback = true it doesnt fire up the onselectedindexchanged event . can someone tell me how to overcome that ?
here is the code snippet for class :
public class DropDown:System.Web.UI.WebControls.DropDownList
the aspx file :
<asp:DropDown ID="ddprojectschedules" runat="server" Font-Bold="True" Font-Size="8pt"
ForeColor="Gray" Width="196px" OnSelectedIndexChanged="ddprojectschedules_SelectedIndexChanged"
and the event :
protected void ddprojectschedules_SelectedIndexChanged(object sender, EventArgs e)
Apr 22, 2011 09:19 PM|Decker Dong - MSFT|LINK
Well, it should work properly. Please check whether your event's name matches the real function's name：）
Here's my sample:
public class Dropdown : DropDownList
public partial class WebForm2 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
protected void Dropdown1_SelectedIndexChanged(object sender, EventArgs e)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplicationTest.WebForm2" %>
<%@ Register assembly="WebApplicationTest" namespace="WebApplicationTest" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<form id="form1" runat="server">
<cc1:Dropdown ID="Dropdown1" runat="server" AutoPostBack="True"
Apr 22, 2011 10:29 PM|jkirkerx|LINK
The 2 code examples show 2 different objects.
The first one is a class, that is incomplete and will never work. It's missing the parameters required to postback such as a handler. You can't just inherit something, until it is created. You have to create it first, then program it, and add it to a collection,
such as htmltextwriter.
The 2nd code example is just a dropdownlist from system.web.ui. But it's missing a event handler to tie the control to an event, and excute some code. Normally you just click on the control in design view, and the code behind page will add an event handler,
in which you type your code in.
There is plenty of sample code in this forum, that should give you insight to the basics of creating server or user controls. Take a look at some of them to gain insight into creating a successful control.