Mar 30, 2011, 7:00 AM
[CLOSED] Javascript error - why cant JS find a Ext control? "<Window> is not defined"
As I posted on the normal forum, here:
http://forums.ext.net/showthread.php...t-defined-quot
----------------------------------------
I want that Javascript should hide a Window.
In my real project, it is not working. So I thought that I make a dummy with the same code approximately so that there was something easy that someone could copy-paste to try out and test. However, the dummy works as expected and its as almost exactly the same code.
So, my not-working page I will present here. The working version, "Test.aspx" follows below.
NOT WORKING VERSION:
Part of Customers.aspx:
We know that the javascript function is called since we get the first alert saying "Test: "...
The only difference I can see between the two is that above we call a code-behind method, DirectEvent, that shows the Windows:
Whats going on?
WORKING VERSION:
http://forums.ext.net/showthread.php...t-defined-quot
----------------------------------------
I want that Javascript should hide a Window.
In my real project, it is not working. So I thought that I make a dummy with the same code approximately so that there was something easy that someone could copy-paste to try out and test. However, the dummy works as expected and its as almost exactly the same code.
So, my not-working page I will present here. The working version, "Test.aspx" follows below.
NOT WORKING VERSION:
Part of Customers.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Secure/Views/View.Master" AutoEventWireup="true" CodeBehind="Customers.aspx.cs" Inherits="WebApplicationExtNetTest.Secure.Views.Customers" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register TagPrefix="CP" TagName="Customer" Src="../UserControls/Customer.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script language="javascript" type="text/javascript">
function CustomerReportCallback(success, errorMsg, customerId) {
alert("Test: " + customerId); // this alert shows!
Window_CreateNewCustomer.hide(); // Here we get an error saying "Uncaught ReferenceError: Window_CreateNewCustomer is not defined"
}
</script>
</asp:Content>
// cut away some stuff
<asp:Content ID="Content3" ContentPlaceHolderID="CPH_west" runat="server">
<ext:Container ID="Container1" runat="server" Layout="Fit" Height="800" MonitorResize="true">
<Content>
// Some stuff
// Nested here somewhere I have a GridPanel and on that a button that shows the Window below as follows:
<ext:GridPanel
ID="GridPanel2"
runat="server"
StoreID="Store_AvailableCustomers">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button ID="btnCreateNewCustomer" runat="server" Icon="Add" Text="Skapa ny kund">
<DirectEvents>
<Click OnEvent="Button_ShowCreateNewCustomer_Click">
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
// more stuff
<ext:Window
ID="Window_CreateNewCustomer"
runat="server"
Icon="New"
Title="Skapa ny kund"
Hidden="true"
Width="480"
Height="370"
Modal="true">
<Content>
<CP:Customer ID="customer_create" runat="server" Title="Skapa ny kund" />
</Content>
</ext:Window>
</Content>
</ext:Container>
</asp:Content>
The UserControl "Customer" in the Window has a button that calls a DirectMethod, and in that DirectMethod we call some stuff that eventually finds its way to the javascript on top, but fails there saying "Uncaught ReferenceError: Window_CreateNewCustomer is not defined".We know that the javascript function is called since we get the first alert saying "Test: "...
The only difference I can see between the two is that above we call a code-behind method, DirectEvent, that shows the Windows:
protected void Button_ShowCreateNewCustomer_Click(object sender, DirectEventArgs e)
{
customer_create._CustomerId = 0;
Window_CreateNewCustomer.Show();
}
while below it is done like:<Click Handler="Window_CreateNewCustomer.show()" />
Actually, when changing the above code to use a Listener instead of DirectEvent, the Window won't show at all:<ext:Button ID="btnCreateNewCustomer" runat="server" Icon="Add" Text="Skapa ny kund">
<Listeners>
<Click Handler="Window_CreateNewCustomer.show()" />
</Listeners>
</ext:Button>
I get "Window_Legitimation is not defined" in the Javascript error console.Whats going on?
WORKING VERSION:
<%@ Page Language="C#" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<script runat="server">
[DirectMethod]
public void CreateNewCustomer()
{
X.Js.Call("CustomerReportCallback", 1, "", 123);
}
</script>
<!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 id="Head1" runat="server">
<title>Show a Hidden Window - Ext.NET Examples</title>
<link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function CustomerReportCallback(success, errorMsg, customerId) {
alert("Test: " + customerId);
Window_CreateNewCustomer.hide();
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<ext:Button
ID="Button3"
runat="server"
Text="Click Listener">
<Listeners>
<Click Handler="Window_CreateNewCustomer.show()" />
</Listeners>
</ext:Button>
<ext:Window
ID="Window_CreateNewCustomer"
runat="server"
Icon="New"
Title="Skapa ny kund"
Hidden="true">
<Content>
<ext:FormPanel ID="FormPanel2" runat="server" Height="330" Width="460" Title="Kundinformation" Padding="5" MonitorResize="true">
<BottomBar runat="server">
<ext:Toolbar ID="Toolbar2" runat="server">
<Items>
<ext:ToolbarFill ID="ToolbarFill2" runat="server" />
<ext:Button ID="Button2" Icon="Disk" Text="Spara" runat="server" >
<Listeners>
<Click Handler="Ext.net.DirectMethods.CreateNewCustomer()" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</BottomBar>
<Content>
<ext:FieldSet ID="FieldSet1"
runat="server"
Title="Grunddata"
AutoHeight="true"
Layout="Form">
<Items>
<ext:CompositeField ID="CompositeField9" runat="server" FieldLabel="Personnr" AnchorHorizontal="100%">
<Items>
<ext:TextField ID="TextField1" runat="server" Width="220" />
</Items>
</ext:CompositeField>
</Items>
</ext:FieldSet>
</Content>
</ext:FormPanel>
</Content>
</ext:Window>
</form>
</body>
</html>
Last edited by Daniil; Apr 09, 2011 at 12:43 PM.
Reason: Marked as [CLOSED]. No more information was provided.