Nesting ASP.NET user controls programmatically - asp.net

I have a user control that programmatically includes a second user control several times, but the end result is that no HTML is generated for the controls at all.
Default.aspx
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestApplication._Default" %>
<%# Register TagName="Ten" TagPrefix="me" Src="~/Ten.ascx" %>
<html>
<head runat="server"></head>
<body>
<form id="form1" runat="server">
<me:Ten ID="thisTen" runat="server" />
</form>
</body>
</html>
Ten.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="Ten.ascx.vb" Inherits="TestApplication.Ten" %>
<asp:Panel ID="List" runat="server"></asp:Panel>
Ten.ascx.vb
Public Class Ten
Inherits System.Web.UI.UserControl
Protected Sub Page_Init() Handles Me.Init
For I As Integer = 0 To 11
List.Controls.Add(New One(I.ToString))
Next
End Sub
End Class
One.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="One.ascx.vb" Inherits="TestApplication.One" %>
<asp:Button ID="OneButton" Text="Press ME!" runat="server" />
One.ascx.vb
Public Class One
Inherits System.Web.UI.UserControl
Private _number As String
Sub New(ByVal number As String)
_number = number
End Sub
Protected Sub OneButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OneButton.Click
Dim script As String = "<script type=""text/javascript"">" +
"alert('Button " + _number + "');" +
"</script>"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ServerControlScript", script, True)
End Sub
End Class
Edit:
Using load control (Ten.aspx)
Dim p() As String = {I.ToString}
Dim o As One = Me.LoadControl(New One("").GetType, p)
List.Controls.Add(o)
Edit 2:
Dim o As One = Me.LoadControl("~/One.ascx")
o._number = I.ToString
List.Controls.Add(o)

I wouldn't perform this operation in the OnInit event, but this may or may not be related to your issue. Instead, I would load the controls in the OnLoad event.
However, using the new keyword is not typically how user controls are loaded. Sorry, but I only know C# and don't know the exact translation:
In C#:
One one = (One)this.LoadControl("~/Controls/One.ascx");
Does this look right in VB.NET?
Dim one As One = Me.LoadControl("~/Controls/One.ascx")
You'll likely have to delete the constructor and just set the property after you load the control.

Related

ASP.NET Webforms Repeater doesn't load custom control properly on button click/postback

I'd like to use a custom control within a repeater with access to the data item of the repeater from within the custom control. This works fine when loading the page, but when binding data to the repeater from a button click event it will not work.
Over the past fwe days I have tried so many different approaches, using ViewStates, Session, disabling ViewState, doing things with and without update panels but I always end at the same issue.
For some reason when binding data on the repeater in the button click event handler the "AssignedValue" property of the custom control will not be set, which works on page load without postback.
I am confused, as the repeater item is present but the custom control is loaded without it being assigned to "AssignedValue". How else would I bind a different data set to the repeater when clicking a button?
Any ideas how I can solve this issue?
Demo solution download: https://drive.google.com/file/d/10TvaCr0p6wPkQ6HoA0PnjwXgYgVJEKp8/view?usp=sharing or see the code below.
Default.aspx
<%# Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<%# Register TagPrefix="test" Src="~/WebUserControl1.ascx" TagName="ctrl" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater runat="server" ID="rptTest" ItemType="WebApplication1.Test">
<ItemTemplate>
<div>
<test:ctrl runat="server" AssignedValue="<%# Item.Value %>" /> (Item: <%# Item.Value %>)
</div>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:LinkButton runat="server" ID="btnLoadMore" OnClick="btnLoadMore_Click">Load More!</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Default.aspx.vb
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
rptTest.DataSource = Test.Set1
rptTest.DataBind()
End If
End Sub
Protected Sub btnLoadMore_Click(sender As Object, e As EventArgs)
rptTest.DataSource = Test.Set2
rptTest.DataBind()
End Sub
End Class
Test.vb
Public Class Test
Public Property Value As String
Public Shared Property Set1 As Test() = {New Test() With {.Value = "a"}, New Test() With {.Value = "b"}}
Public Shared Property Set2 As Test() = {New Test() With {.Value = "c"}, New Test() With {.Value = "d"}}
End Class
WebUserControl1.aspx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="WebApplication1.WebUserControl1" %>
Value: <asp:Literal runat="server" ID="litValue" />
WebUserControl.aspx.vb
Public Class WebUserControl1
Inherits System.Web.UI.UserControl
Public Property AssignedValue As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
litValue.Text = AssignedValue
End Sub
End Class
What I expect:
Value: a (Item: a)
Value: b (Item: b)
*Click on Load More!*
Value: c (Item: c)
Value: d (Item: d)
What I get:
Value: a (Item: a)
Value: b (Item: b)
*Click on Load More!*
Value: (Item: c)
Value: (Item: d)
Hi I have looked at your code and i think i know what the problem is.
in the WebUserControl1.ascx.vb you assign a value on Page_load so it works the first time but then on the binding the second time you don't assign a value so you need to add the assignment below WebUserControl1 prerender. Please let me know if it works. Fingers crossed.
Public Class WebUserControl1
Inherits System.Web.UI.UserControl
Public Property AssignedValue As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
litValue.Text = AssignedValue
End Sub
Private Sub WebUserControl1_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
litValue.Text = AssignedValue
End Sub
End Class
I'm not sure if this will help but I had a problem with repeaters before in UpdatePanels and was getting a pull page reload instead of a partial one so losing data.
The repeaters don't seem to handle client ids very well so it caused me problems.
I added ClientIDMode="AutoID" to the repeaters attributes which fixed the problem for me.
It may be worth a try. Somebody else may be able to explain this technically better thank me.

How to access value in one Ascx control in another Ascx control on the same page

I have a aspx page that has two user controls one with a grid view in it and another with a label in it which is used for displaying user data when he logs in. Now I want use the data from one column in the grid view to be displayed in the label in second user control. How can I achieve this. The data in the gridview changes for each user based up on his security role.any inputs appreciated. Thank you
Gridview user control raises a custom event when it has the information you need. The event is handled in the main page and assigned to the UserControl with a label via a public property that has access to the Label Text embedded within the control.
Default.aspx
Page with both user controls
<%# Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="StackOverFlowJunkVB._Default" %>
<%# Register Src="~/WebUserControlGridView1.ascx" TagPrefix="uc1" TagName="WebUserControlGridView1" %>
<%# Register Src="~/WebUserControlLabel1.ascx" TagPrefix="uc1" TagName="WebUserControlLabel1" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<uc1:WebUserControlGridView1 runat="server" id="WebUserControlGridView1" />
<uc1:WebUserControlLabel1 runat="server" id="WebUserControlLabel1" />
</asp:Content>
Default.aspx.vb
Code behind that assigns text to Label user control via raised event from GridView user control
Public Class _Default
Inherits Page
Private Sub WebUserControlGridView1_ReallyImportantLabelTextHandler(sender As Object, e As GridViewLabelEvent) _
Handles WebUserControlGridView1.ReallyImportantLabelTextHandler
WebUserControlLabel1.ReallyImportLabelText = e.ImportantLabelText
End Sub
End Class
CodeBehind for the GridView UserControl
' Define a custom EventArgs class to pass some really important text
Public Class GridViewLabelEvent
Inherits EventArgs
Public Property ImportantLabelText As String
End Class
' The user control with a GridView
Public Class WebUserControlGridView1
Inherits System.Web.UI.UserControl
Public Event ReallyImportantLabelTextHandler As EventHandler(Of GridViewLabelEvent)
Private Sub GridView1_DataBound(sender As Object, e As EventArgs) Handles GridView1.DataBound
Dim gvle As New GridViewLabelEvent
gvle.ImportantLabelText = "This is really important"
RaiseEvent ReallyImportantLabelTextHandler(Me, gvle)
End Sub
End Class
CodeBehind for the Label UserControl
Public Class WebUserControlLabel1
Inherits System.Web.UI.UserControl
' Property to assign Label Text
Public Property ReallyImportLabelText As String
Get
Return Label1.Text
End Get
Set(value As String)
Label1.Text = value
End Set
End Property
End Class

Dynamic controls added to my content page during the preinit event do not maintain viewstate

I've added a few dynamic controls to my content page during the PreInit event, however the Viewstate is not being maintained automatically after postback, despite what is claimed about adding controls during the PreInit event. My drop down list and textbox reset. What am I doing wrong?
Mark Up
<%# Page Title="" Language="VB" MasterPageFile="~/ContentPages/MasterPage.master" AutoEventWireup="false" CodeFile="ElktonOEE.aspx.vb" Inherits="ContentPages_OEE_ElktonOEE" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_Head" Runat="Server">
<link rel="stylesheet" href="http://flexweb/MES/css/UserControls/FlexGridView.css" type="text/css"/>
<link rel="stylesheet" href="http://flexweb/MES/css/LabelTexbox.css" type="text/css"/>
<link rel="stylesheet" href="http://flexweb/MES/css/OEE.css" type="text/css"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder_PageContentTitle" Runat="Server">
<div class="PageContentTitle">OEE Report</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder_Content" Runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<script type="text/javascript">
</script>
<div class="MESContentDiv" id="SqlQueryContentDiv">
<div id="ContentLabelDiv">
<asp:Label ID="PanelLabel" runat="server" CssClass="ContentLabel"></asp:Label>
</div>
<br />
<asp:Panel ID="Panel1" runat="server">
<!-- Controls dynamically generated in the code-behind and inserted here -->
</asp:Panel>
<br />
<br />
<asp:Panel ID="Panel2" runat="server">
<asp:Table ID="Table1" runat="server">
</asp:Table>
</asp:Panel>
</div>
</asp:Content>
Code Behind
Imports ASP 'Allows User Control to be dynamically loaded onto page
Imports System.Data 'Allows namespace access to the DataSet class
Imports System.Web.UI.UserControl
Imports MES_Class_Library
Partial Class ContentPages_OEE_ElktonOEE
Inherits System.Web.UI.Page
Protected Sub Page_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
'Call this to avoid null result when searching for controls on a content page
CommonFlexwebFunctions.PrepareChildControlsDuringPreInit(Page)
'Add Dynamic Controls, Dyanimc Controls Must be given ID in order for the viewstate to work.
LoadSearchPrompt()
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Label_Debug.Visible = False
'Prompt for parameters
PanelLabel.Text = "Select OEE Parameters"
'Check for empty Query String
If (Request.QueryString("Type") IsNot Nothing) And (Request.QueryString("Date") IsNot Nothing) Then
Select Case Request.QueryString("Type")
Case "Daily"
LoadDailySummary()
Case "Weekly"
'LoadWeeklySummary()
Case "Monthly"
'LoadMonthlySummary()
End Select
Else
Panel2.Visible = False
End If
End Sub
Private Sub LoadSearchPrompt()
Dim lb1, lb2 As New Label
Dim ddl As New DropDownList
Dim tb As New TextBox
Dim ce As New AjaxControlToolkit.CalendarExtender
Dim validation_groupname As String = "ValidDate"
'Report Label
lb1.CssClass = "LabelName125 Twelve"
lb1.ID = "lbType"
lb1.Text = "Report Type:"
'Report DDL
ddl.CssClass = "ML5"
ddl.ID = "ddlReportType"
ddl.Items.Add("--")
ddl.Items.Add("Daily")
ddl.Items.Add("Weekly")
ddl.Items.Add("Monthly")
'Start Date Label
lb2.CssClass = "LabelName125 Twelve"
lb2.ID = "lbDate"
lb2.Text = "Start Date:"
'Start Date Textbox
tb.CssClass = "TextboxValue125 ML5"
tb.ID = "textboxStartDate"
tb.ValidationGroup = validation_groupname
'Calendar Extender
ce.ID = "ceDate"
ce.TargetControlID = "textboxStartDate"
'Valiation
Dim cv As New CompareValidator
Dim vs As New ValidationSummary
cv.ControlToValidate = "textboxStartDate"
cv.ID = "cv1"
cv.Display = ValidatorDisplay.None
cv.ErrorMessage = "Date must be in the mm/dd/yyyy format."
cv.Operator = ValidationCompareOperator.DataTypeCheck
cv.Type = ValidationDataType.Date
cv.ValidationGroup = validation_groupname
vs.ID = "vs1"
vs.HeaderText = "The data you entered contains an error."
vs.ShowMessageBox = True
vs.ShowSummary = False
vs.ValidationGroup = validation_groupname
'Submit
Dim btn As New Button
btn.CssClass = "Button100 LeftMargin25"
btn.ID = "btnSubmit"
btn.CausesValidation = True
btn.ValidationGroup = validation_groupname
btn.Text = "Submit"
'add handler
AddHandler btn.Click, AddressOf MyBtnClick '' this is the method to call
'Add Controls
Panel1.Controls.Add(lb1)
Panel1.Controls.Add(ddl)
Panel1.Controls.Add(lb2)
Panel1.Controls.Add(tb)
Panel1.Controls.Add(ce)
Panel1.Controls.Add(cv)
Panel1.Controls.Add(vs)
Panel1.Controls.Add(btn)
End Sub
Private Sub MyBtnClick(ByVal sender As Object, ByVal e As EventArgs)
Dim btn As Button = CType(sender, Button) ''Gets the button that fired the method
Dim ReportType As String = ""
Dim StartDate As String = ""
'Access the ddl
Dim ddl As DropDownList = CType(CommonFlexwebFunctions.RecursiveFindControl(Page, "ddlReportType"), DropDownList)
'If the proper ddl was found, set its value
If ddl IsNot Nothing Then
'Set the value
ReportType = ddl.SelectedItem.ToString()
End If
'Access the tb
Dim tb As TextBox = CType(CommonFlexwebFunctions.RecursiveFindControl(Page, "textboxStartDate"), TextBox)
'If the proper ddl was found, set its value
If tb IsNot Nothing Then
'Set the value
StartDate = tb.Text
End If
Response.Redirect("ElktonOEE.aspx?Type=" + ReportType + "&Date=" + StartDate)
End Sub
Private Sub LoadDailySummary()
Panel2.Visible = True
End Sub
End Class
Class Functions
Public Class CommonFlexwebFunctions
Public Shared Function RecursiveFindControl(container As Control, name As String) As Control
If Not (container.ID Is Nothing) AndAlso (container.ID.Equals(name)) Then
Return container
End If
For Each c As Control In container.Controls
Dim ctrl As Control = RecursiveFindControl(c, name)
If Not ctrl Is Nothing Then
Return ctrl
End If
Next
Return Nothing
End Function
Public Shared Sub PrepareChildControlsDuringPreInit(page As Page)
' Walk up the master page chain and tickle the getter on each one
' Run this so you can see the controls on content pages
Dim master As MasterPage = page.Master
While master IsNot Nothing
master = master.Master
End While
End Sub
End Class
The problem might be related to the fact that ToolkitScriptManager by default uses host aspx page url to reference it's controls scripts. Thus page's PreInit event is executed twice.
In order to avoid it - just follow the instruction provided below to instruct ScriptManager to use it's handler instead of the page's URL
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ToolkitScriptManager/ToolkitScriptManager.aspx

Bind Property of ASP.NET User Control to One of the Parent Control's Fields

If I need access to the value of a user control's property BEFORE PreRender, would I need to base the custom control off of one of the preexisting data controls (repeater, listview, etc.)?
One of my user controls features a gridview control that is configured based on the user control's properties on which it resides. Several of the key properties alter the SQL Statement for the underlying recordsource. I'm now in a situation where the property that sets the WHERE statement for the SQL Statement needs to tied to a value in the user control's parent FormView. Think of the formview as displaying a customer detail record. The user control takes the customer's account number and then displays data from a related table such as Customer Contact Names. Since the gridview is created before the control's prerender event, working within the prerender event doesn't seem efficient.
See this question as a reference:
Stumped With Custom Property on User Control
What I said that you can assign value to the parent control when user control binds.
TestIt.ascx - Markup
<%# Control Language="VB" AutoEventWireup="false"
CodeFile="TestIt.ascx.vb" Inherits="usercontrols_TestIt" %>
<asp:Label
ID="lblOne"
runat="server">
</asp:Label>
TestIt.ascx.vb
Partial Class usercontrols_TestIt
Inherits System.Web.UI.UserControl
Public Property No As Integer
Get
Dim mno As Integer = 0
Integer.TryParse(lblOne.Text, mno)
Return mno
End Get
Set(value As Integer)
lblOne.Text = value.ToString()
End Set
End Property
Public ReadOnly Property Square As Integer
Get
Return No * No
End Get
End Property
Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
'Get ref. of parent control
Dim row As FormViewRow = CType(Parent.Parent, FormViewRow)
'Find control in parent control
Dim sqLabel As Label = row.FindControl("Label2")
'Assign value
sqLabel.Text = Square.ToString()
End Sub
End Class
ASPX - Markup
<%# Page Language="VB" AutoEventWireup="false" CodeFile="VbDefault2.aspx.vb" Inherits="usercontrols_VbDefault2" %>
<%# Register src="TestIt.ascx" tagname="TestIt" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True">
<ItemTemplate>
No :
<uc1:TestIt ID="TestIt1" runat="server" No='<%#Eval("No") %>'
ClientIDMode="AutoID" />
<br />
Square :
<asp:Label ID="Label2" runat="server" ></asp:Label>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
ASPX.vb
Partial Class usercontrols_VbDefault2
Inherits System.Web.UI.Page
Public Class TestData
Public Property No As Integer
End Class
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim nos As New List(Of TestData)
nos.Add(New TestData() With {.No = 10})
nos.Add(New TestData() With {.No = 20})
FormView1.DataSource = nos
FormView1.DataBind()
End Sub
Protected Sub FormView1_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles FormView1.PageIndexChanging
FormView1.PageIndex = e.NewPageIndex
BindData()
End Sub
End Class

Declarative event handling from ASP.NET user control to page

I am trying to figure out how to declaratively pass in a event handler into
a user control, but I am stumped. All I can make work is the user control's
event handler.. I can't seem to bubble up the caught event into the parent
page. Ideas would be quite welcome. Here is my code:
Default.aspx:
<%# Page Language="VB" %>
<%# Register TagPrefix="rpt" TagName="filter" Src="WebUserControl.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Controls</title>
</head>
<body>
<form id="form1" runat="server">
<rpt:filter ID="DataView1Filters" runat="server" SelectedIndexChanged="DropDown_SelectedIndexChanged" />
<asp:Label ID="Label1" runat="server" />
</form>
<script runat="server">
Public Sub DropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = String.Format("Inside declarative event handler. {0}<br>", Label1.Text)
End Sub
</script>
</body>
</html>
WebUserControl.ascx:
<%# Control Language="VB" ClassName="WebUserControlTest" %>
<asp:Panel ID="TestPanel" runat="server"></asp:Panel>
<script runat="server">
Private AllEvents As New System.ComponentModel.EventHandlerList
Public Custom Event SelectedIndexChanged As EventHandler
AddHandler(ByVal value As EventHandler)
AllEvents.AddHandler("SelectedIndexChanged", value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
AllEvents.RemoveHandler("SelectedIndexChanged", value)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
Dim value As EventHandler = CType(AllEvents("SelectedIndexChanged"), EventHandler)
If Not value Is Nothing Then
value.Invoke(sender, e)
End If
End RaiseEvent
End Event
Private Sub _SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim ctrl As DropDownList = Me.FindControl("TestDropDownList")
If Not ctrl Is Nothing Then
Me.ViewState("ItemSelection") = ctrl.SelectedIndex
End If
Dim Label1 As Label = Parent.FindControl("Label1")
Label1.Text = String.Format("Inside user control event handler. {0}<br>", Label1.Text)
RaiseEvent SelectedIndexChanged(sender, e)
End Sub
Private Overloads Sub OnLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ctrl As New DropDownList
With ctrl
.ID = "TestDropDownList"
.Items.Clear()
.AutoPostBack = True
AddHandler .SelectedIndexChanged, AddressOf _SelectedIndexChanged
.Items.Add(New ListItem("-- Select --", String.Empty))
.Items.Add(New ListItem("Item 1", "1"))
.Items.Add(New ListItem("Item 2", "2"))
If Not Me.ViewState("ItemSelection") Is Nothing Then
.SelectedIndex = CInt(Me.ViewState("ItemSelection"))
Else
.SelectedIndex = 0
End If
End With
TestPanel.Controls.Add(ctrl)
End Sub
</script>
Thanks!
See this previous post:
Handling User Control Events on Containing Page
Edit - added based on your comment
I should have read the question more clearly.
As far as having a UserControl raise an event that the containing page can respond to, I do not believe that this can be done declaratively.
Unless my knowledge is just lacking, the only way to accomplish this is by explicitly creating an event in the control and then handling it (by coding the event handler) on the parent page, as shown in the example I linked to.
I was recently having this same issue in C#. When you set up an event called SelectedIndexChanged asp.net will bind the attribute OnSelectedIndexChanged when using the declarative syntax.
So if you change
<rpt:filter ID="DataView1Filters" runat="server" SelectedIndexChanged="DropDown_SelectedIndexChanged" />
To
<rpt:filter ID="DataView1Filters" runat="server" OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />
It should work.

Resources