May 29, 2011, 1:33 PM
[CLOSED] Dynamic usercontrol and execute javascript
I have a page with a masterpage, within the page a button with a directevent which loads a usercontrol. In that usercontrol I have a window with a button.
When I click the button in the window I want to execute a javascript function defined in the usercontrol.
The problem is when I click the button I get a javascript Error: 'showAlert' is undefined also the window icon is not rendered.
Hoe can I load a usercontrol dynamically which contains a window into a child page and use javascript within the usercontrol?
masterpage.aspx
When I click the button in the window I want to execute a javascript function defined in the usercontrol.
The problem is when I click the button I get a javascript Error: 'showAlert' is undefined also the window icon is not rendered.
Hoe can I load a usercontrol dynamically which contains a window into a child page and use javascript within the usercontrol?
masterpage.aspx
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!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></title>
<ext:resourceplaceholder runat="server" />
</head>
<body>
<ext:resourcemanager runat="server" id="ResourceManager1" idmode="Explicit" />
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Default.aspx<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register TagPrefix="uc1" TagName="WebUserControl" Src="WebUserControl.ascx" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ext:panel id="MainPanel" runat="server" height="300" title="Title">
<Items>
<ext:Button ID="btnOpen" runat="server" Text="Submit">
<DirectEvents>
<Click OnEvent="OpenClicked" />
</DirectEvents>
</ext:Button>
</Items>
</ext:panel>
</asp:Content>
Default.aspx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
public partial class Default : System.Web.UI.Page
{
public void OpenClicked(object sender, Ext.Net.DirectEventArgs e)
{
var ctl = (WebUserControl)Page.LoadControl("WebUserControl.ascx");
MainPanel.ContentControls.Add(ctl);
ctl.Render();
}
}
WebUserControl.ascx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script>
function showAlert() {
alert("test");
}
</script>
<ext:Window ID="popupwindow" runat="server" Collapsible="true" Height="185" Icon="Application" Title="Title" Width="350"
InitCenter="false">
<Items>
<ext:Button runat="server" Text="Alert">
<Listeners>
<Click Handler="showAlert()" />
</Listeners>
</ext:Button>
</Items>
</ext:Window>
WebUserControl.ascx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class WebUserControl : System.Web.UI.UserControl
{
public void Render()
{
this.popupwindow.Render();
}
}
Last edited by Daniil; May 31, 2011 at 10:53 AM.
Reason: [CLOSED]