Solved

Drop down does not fire event in Ajax modal popup

Posted on 2010-11-17
4
1,540 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

11 Experts available now in Live!

Get 1:1 Help Now