Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Drop down does not fire event in Ajax modal popup

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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, …
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 Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

564 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