?
Solved

Drop down does not fire event in Ajax modal popup

Posted on 2010-11-17
4
Medium Priority
?
1,752 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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