Solved

Drop down does not fire event in Ajax modal popup

Posted on 2010-11-17
4
1,568 Views
1 Endorsement
Last Modified: 2012-05-10
i have a user control which is displayed in the Ajax Modal popup when i click a button.
the user control has a drop down.. the drop down selected index changed event does not does not fire.. any help how to do it.. thanks
1
Comment
Question by:gautam_reddyc
  • 3
4 Comments
 
LVL 20

Expert Comment

by:ddayx10
ID: 34161123
There is no inherant reason that setup should not work. If I were to guess from the limited info it would be that you didnt enable autopostback on the dropdownlist, but I'm just guessing. I put together a sample of the setup you described and maybe you can figure it out from that.
****ASPX PAGE****

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ModalWithDDL.aspx.vb" Inherits="ModalWithDDL" %>



<%@ Register src="ModalStuff.ascx" tagname="ModalStuff" 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>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="sm" runat="server" EnablePartialRendering="true" />

		<uc1:ModalStuff ID="ModalStuff1" runat="server" />

	</form>

</body>

</html>****ASCX PAGE****

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ModalStuff.ascx.vb" Inherits="ModalStuff" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <asp:Button ID="BtnFire" runat="server" Text="Fire Modal" />

    <asp:Label ID="LbSelectedText" runat="server" />

    <asp:Panel ID="PnlModal" runat="server">

		<asp:DropDownList ID="DdlModal" runat="server" AutoPostBack="true">

			<asp:ListItem Text="Item1" Value="0" />

			<asp:ListItem Text="Item2" Value="1" />

		</asp:DropDownList>

		<div>

		<asp:Button ID="BtnOK" runat="server" Text="OK" />

		<asp:Button ID="BtnCnl" runat="server" Text="Cancel" />

		</div>

    </asp:Panel>

	<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"

      TargetControlID="BtnFire"

      PopupControlID="PnlModal"

      CancelControlID="BtnCnl"

      OkControlID="BtnOK">

	</cc1:ModalPopupExtender>



****ASCX.VB CODE BEHIND****

    Protected Sub DdlModal_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlModal.SelectedIndexChanged

        LbSelectedText.Text = DdlModal.SelectedItem.Text

    End Sub

Open in new window

0
 
LVL 20

Expert Comment

by:ddayx10
ID: 34161215
After reading your description again I've changed it around. This setup may more acurrately reflect your setup. Page with modal, in modal is usercontrol, on usercontrol is dropdownlist with onselectedindexchanged event set to update label on main page.
****ASPX PAGE****

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ModalWithDDL.aspx.vb" Inherits="ModalWithDDL" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register src="ModalStuff.ascx" tagname="ModalStuff" 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>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="sm" runat="server" EnablePartialRendering="true" />

    <asp:Button ID="BtnFire" runat="server" Text="Fire Modal" />

    <asp:Label ID="LbSelectedText" runat="server" />

    <asp:Panel ID="PnlModal" runat="server">

		<uc1:ModalStuff ID="ModalStuff1" runat="server" />

		<div>

		<asp:Button ID="BtnOK" runat="server" Text="OK" />

		<asp:Button ID="BtnCnl" runat="server" Text="Cancel" />

		</div>

    </asp:Panel>

	<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"

      TargetControlID="BtnFire"

      PopupControlID="PnlModal"

      CancelControlID="BtnCnl"

      OkControlID="BtnOK">

	</cc1:ModalPopupExtender>    

	</form>

</body>

</html>



****ASCX PAGE****

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ModalStuff.ascx.vb" Inherits="ModalStuff" %>

<asp:DropDownList ID="DdlModal" runat="server" AutoPostBack="true">

	<asp:ListItem Text="Item1" Value="0" />

	<asp:ListItem Text="Item2" Value="1" />

</asp:DropDownList>



***ASCX.VB CODE BEHIND****

Partial Class ModalStuff

    Inherits System.Web.UI.UserControl

    Protected Sub DdlModal_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlModal.SelectedIndexChanged

        DirectCast(Page.FindControl("LbSelectedText"), Label).Text = DdlModal.SelectedItem.Text

    End Sub

End Class

Open in new window

0
 

Author Comment

by:gautam_reddyc
ID: 34166239
Hi ddayx10,
    Thanks for the info. I have autopost back enabled. I am not able to fire the event..
    I have around 4 user controls which are loaded dynamically depending on which button is clicked.
   and the user control is placed in the update panel..

   if i have only one user control and register it in the page like you mentioned .. it is working fine..
   but the problem is i have 4 user controls and they are loaded into the modal popup extender dynamically.. i guess that's the reason it is not firing the events..

   Do i have to use events and delegates to fire the dropdownlist selected index change. pls help.

 
0
 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
ID: 34168942
Ok well that's more info than I had before, but it still doesn't explain the issue. Adding a usercontrol dynamically will automatically register the events (at least in all the attempts I've tried). I didn't know about the update panel before, but even considering that it works fine under several tests I've made (see new code below).

The only way this doesn't work is if I set my update panel's UpdateMode property to "conditional" and set ChildrenAsTriggers to false without having any triggers created.

Without seeing your update panel, and/or the way you are adding the usercontrols (I added both in page_load and page_init) I can't do much more than guess.

Make a new page, replicate the basics or your update panel, and how you are adding the usercontrols. Test it and see if it works. Simplify your update panel settings until you get it working. Feel free to post your code here.
***ASPX PAGE***

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ModalWithDDL.aspx.vb" Inherits="ModalWithDDL" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>



<!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>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="sm" runat="server" />

    

    <asp:UpdatePanel ID="Up1" runat="server">

		<ContentTemplate>

			<asp:Button ID="BtnFire" runat="server" Text="Fire Modal" />

			<asp:Label ID="LbSelectedText" runat="server" />

			<asp:Panel ID="PnlModal" runat="server">

				<div>

					<asp:Button ID="BtnOK" runat="server" Text="OK" />

					<asp:Button ID="BtnCnl" runat="server" Text="Cancel" />

				</div>

			</asp:Panel>

			<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"

				TargetControlID="BtnFire"

				PopupControlID="PnlModal"

				CancelControlID="BtnCnl"

				OkControlID="BtnOK">

			</cc1:ModalPopupExtender>   

		</ContentTemplate>

	</asp:UpdatePanel>

    



 

	</form>

</body>

</html>



***ASPX.VB CODE BEHIND***



Partial Class ModalWithDDL

    Inherits System.Web.UI.Page



    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        Dim uc As UserControl = LoadControl("modalstuff.ascx")

        PnlModal.Controls.Add(uc)

    End Sub

End Class



****ASCX PAGE****

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ModalStuff.ascx.vb" Inherits="ModalStuff" %>

<asp:DropDownList ID="DdlModal" runat="server" AutoPostBack="true">

	<asp:ListItem Text="Item1" Value="0" />

	<asp:ListItem Text="Item2" Value="1" />

</asp:DropDownList>



****ASCS.VB CODE BEHIND****



Partial Class ModalStuff

    Inherits System.Web.UI.UserControl

    Protected Sub DdlModal_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlModal.SelectedIndexChanged

        DirectCast(Page.FindControl("LbSelectedText"), Label).Text = DdlModal.SelectedItem.Text

    End Sub

End Class

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A short film showing how OnPage and Connectwise integration works.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now