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

i have asp.net 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.

Thanks
Posted

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.
C#
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.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>
<%@ Register Src="~/TestUserControl.ascx" TagPrefix="uc" TagName="List" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc:list id="uxUcList" runat="server" onselectedindexchanged="uxUcList_SelectedIndexChanged" />
    </div>
    </form>
</body>
</html>

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

Try this demo it will be clear when using it.
 
Share this answer
 
v4

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