Click here to Skip to main content
14,870,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i have web application using c#.

Where i have created one web user control, in this web user control i have dropdowlist and textboxes,
and also i have dropdownlist selectedindexchanged event in this web user control.

i'm using this web user control in a repeater.

i'm able to find all the controls i had in the web user control.

But how can i find the dropdownlist selectedIndexChanged event.

Please, suggest me.


1 solution

Define a specific event for that control. Let you have a user control TestUserControl.ascx having dropdownlist as uxDemoList allow AutoPostBack="true" for uxDemoList control. In code behind your code can be stated bellow.
public delegate void SelectedIndexChangedHandler(object sender, EventArgs e);
public event SelectedIndexChangedHandler SelectedIndexChanged;

protected void uxDemoList_SelectedIndexChanged(object sender, EventArgs e)
    if (SelectedIndexChanged != null)
        SelectedIndexChanged(sender, e);

    Response.Write("<br />In User Control.");

Now add this control in aspx page say TestPage.aspx as shown below.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>
<%@ Register Src="~/TestUserControl.ascx" TagPrefix="uc" TagName="List" %>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <uc:list id="uxUcList" runat="server" onselectedindexchanged="uxUcList_SelectedIndexChanged" />

Its code behind will be.
protected void uxUcList_SelectedIndexChanged(object sender, EventArgs e)
    Response.Write("<br />In Page.");

Try this demo it will be clear when using it.

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