Solved

Drop down does not fire event in Ajax modal popup

Posted on 2010-11-17
4
1,653 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

761 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