May 23, 2011, 12:22 PM
[CLOSED] Not able to access Ext controls and static DirectMethods from JavaScript during Initial Request
Hi,
I am not able to acces the Ext controls or static DirectMethods from javascript during the Initial Page request. This is how i am trying to access.
A web page that hosts the user control.
WebPage ASPX Code:
User Control ASCX
Java Script code:
Regards.
Manoj
I am not able to acces the Ext controls or static DirectMethods from javascript during the Initial Page request. This is how i am trying to access.
A web page that hosts the user control.
WebPage ASPX Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="LearnExtNet.WebForm3" %>
<%@ Register src="WebUserControl2.ascx" tagname="WebUserControl2" 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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
</div>
<uc1:WebUserControl2 ID="WebUserControl21" runat="server" />
</form>
</body>
</html>
Web Page Code Behind Code: public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[DirectMethod]
public static void LogException(string e)
{
// Log the Exception
}
}
The user control actually renders a dynamic control inside <DIV> using the javascript. User Control ASCX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs"
Inherits="LearnExtNet.WebUserControl2" %>
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="JScript1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
sendRequestOnDocReady();
});
</script>
<div id="container"></div>
<ext:Panel ID="panError" runat="server" Height="300" Title="Error" Hidden="true">
<Content>
An error Occured.
</Content>
</ext:Panel>
User Control Code Behind:public partial class WebUserControl2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterExpandoAttribute(container.ClientID, "panErrorId", panError.ClientID);
}
[DirectMethod]
public static void LogException(string e)
{
// Log the Exception
}
}
The JavaScript function called during the document ready event of the user control.Java Script code:
function sendRequestOnDocReady(controlId) {
try {
// render the dynamic control in the given control
//
// code.....
// if suppose an exception occurs here
//
throw "Error";
} catch (e) {
// here i want to show the error in the Ext panel that was present in the user control as hidden control.
// But, I am not able access this control using Ext.getCmp
//
var container = document.getElementById(controlId);
var errorPan = Ext.getCmp(container.panErrorId); // I tried Ext.get() also it is not working
// I want to log the exception here but the static DirectMethod is undefined here
//
Ext.net.DirectMethods.LogException(e);
}
}
The JavaScript code describes where exactly i was facing the problem. Please read the comments in the JavaScript. Can you please let me know why i am not able to acccess the Ext Panel and static DirectMethods from this javascript method.Regards.
Manoj
Last edited by Daniil; May 23, 2011 at 1:34 PM.
Reason: Repaired [CODE] tags, [CLOSED]