PDA

View Full Version : [CLOSED] DirectMethod in a MasterPage



amitpareek
Jul 11, 2013, 8:25 PM
Hi,
When I am trying to call Direct Method declared in a MasterPage I get the following error :

The ajax instance method 'TEST' is absent!

Here's the code. Try calling DM.Test()

Page.aspx:


<%@ Page Title="" Language="C#" MasterPageFile="~/system/templates/browser.master" AutoEventWireup="true" CodeBehind="accident.aspx.cs" Inherits="Web.ui.browsers.accident" %>
<%@ MasterType VirtualPath="~/system/templates/browser.master" %>


MasterPage.aspx


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
namespace Web.ui.browsers
{
public partial class accident : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}


}
}


MasterPage


<%@ Master Language="C#" MasterPageFile="~/system/templates/content.master" AutoEventWireup="true" CodeBehind="browser.master.cs" Inherits="Web.system.templates.browser" %>


<asp:Content ID="Content1" ContentPlaceHolderID="innerhead" runat="server">
<script src="../../global/js/browser.js"></script>
<style type="text/css">
.x-grid-row-summary .x-grid-cell-inner {
font-weight: bold;
font-size: 11px;
background-color : #f1f2f4;
}
</style>


</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="innercontent" runat="server">
<ext:Viewport runat="server" ID="browserViewport" Layout="FitLayout">
</ext:Viewport>
</asp:Content>


MasterPage.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Browser;
using Ext.Net;
using Newtonsoft.Json;


namespace Web.system.templates
{
[DirectMethodProxyID(IDMode = DirectMethodProxyIDMode.None)]
public partial class browser : System.Web.UI.MasterPage
{


protected void Page_Load(object sender, EventArgs e)
{
}




[DirectMethod]
public string TEST()
{


return "a";
}



}
}

Baidaly
Jul 12, 2013, 12:19 AM
I don't see your ResourceManager. Also, why do you use DM namespace for DirectMethods? Also, it's better to use special wildcard #{DirectMethods}. I've tried with the following sample and it works:

MasterPage.aspx


<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Ext.Net.Examples.Site1" %>

<script runat="server">
[DirectMethod]
public void DoSomething()
{
X.Msg.Notify("Time", DateTime.Now.ToLongTimeString()).Show();
}
</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ext.NET Example</title>
<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</form>
</body>
</html>


MasterPage.aspx.cs


[DirectMethodProxyID(IDMode = DirectMethodProxyIDMode.None)]
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}


Page:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Ext.Net.Examples.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<ext:Button runat="server" Text="Submit" OnClientClick="#{DirectMethods}.DoSomething();" />
</asp:Content>

Daniil
Jul 12, 2013, 6:35 AM
Hi,

Be careful with #{DirectMethods}. It might not work in some complex scenarios.

amitpareek
Jul 12, 2013, 9:12 AM
Hi Baidaly,
I missed the the resource manager. Please test using the code I sent with the following MasterPage. It does'nt work.
Also, I user DirectMethodNamespace to keep my DirectMethods organised. I don't see why that should be an issue. There is something else I am missing, which I cannot figure. Can you run my exactly my sample with the folliwng master page.



<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="browser.master.cs" Inherits="Web.system.templates.browser" %>


<asp:Content ID="Content1" ContentPlaceHolderID="innerhead" runat="server">
<script src="../../global/js/browser.js"></script>
<style type="text/css">
.x-grid-row-summary .x-grid-cell-inner {
font-weight: bold;
font-size: 11px;
background-color : #f1f2f4;
}
</style>


</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="innercontent" runat="server">
<ext:ResourceManager ID="extrm" runat="server" DirectMethodNamespace="DM">
</ext:ResourceManager>
<ext:Viewport runat="server" ID="browserViewport" Layout="FitLayout">
</ext:Viewport>
</asp:Content>




I don't see your ResourceManager. Also, why do you use DM namespace for DirectMethods? Also, it's better to use special wildcard #{DirectMethods}. I've tried with the following sample and it works:

MasterPage.aspx


<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Ext.Net.Examples.Site1" %>

<script runat="server">
[DirectMethod]
public void DoSomething()
{
X.Msg.Notify("Time", DateTime.Now.ToLongTimeString()).Show();
}
</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ext.NET Example</title>
<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</form>
</body>
</html>


MasterPage.aspx.cs


[DirectMethodProxyID(IDMode = DirectMethodProxyIDMode.None)]
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}


Page:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Ext.Net.Examples.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<ext:Button runat="server" Text="Submit" OnClientClick="#{DirectMethods}.DoSomething();" />
</asp:Content>

Daniil
Jul 12, 2013, 12:55 PM
I am getting this exception: Content controls are allowed only in content page that references a master page.

Indeed, I see <asp:Content> in the MasterPage, but it seems has not reference to another MasterPage.

amitpareek
Jul 12, 2013, 3:07 PM
Hi Daniil,
My mistake. I will put up everything together in one zip file and send it to you.

Thanks,

Daniil
Jul 12, 2013, 4:46 PM
If possible, it would be better to post the required things here wrapping in
tags.

To avoid many code snippets, you can place code behind directly on ASPX pages by wrapping in
[CODE]<script runat="server">
// code behind stuff
</script>

amitpareek
Jul 12, 2013, 9:02 PM
Hi Daniil,
Please check the following:

I observed that, having if I have resourcemanager in text.aspx page, everything works well, but if I have resource manager in base.master, DirectMethod registers on client side, but throws the exception on execution. Please check for yourself by running test.aspx. Do the following :

1) Run test.aspx
2) Call DM.Test() from the JS console.

base.MASTER


<%@ Master Language="C#" AutoEventWireup="true" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
<body>
<form id="frm" runat="server">
<div>
<ext:ResourceManager ID="extrm" runat="server" DirectMethodNamespace="DM">
</ext:ResourceManager>
<asp:ContentPlaceHolder ID="content" runat="server" />
</div>
</form>
</body>
</html>


content.MASTER


<%@ Master Language="C#" MasterPageFile="~/system/templates2/base.master" AutoEventWireup="true"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:ContentPlaceHolder ID="innerhead" runat="server" />
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
<asp:ContentPlaceHolder ID="innercontent" runat="server" />
</asp:Content>


browser.MASTER


<%@ Master Language="C#" MasterPageFile="~/system/templates2/content.master" AutoEventWireup="true"%>
<script runat="server">
[DirectMethod]
public string TEST()
{
Ext.Net.MultiSelect t = new MultiSelect();
Ext.Net.Panel p = new Ext.Net.Panel();
p.Add(t);
return p.ToScript();
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="innerhead" runat="server">

</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="innercontent" runat="server">
<ext:Viewport runat="server" ID="browserViewport" Layout="FitLayout">
</ext:Viewport>
</asp:Content>


test.aspx


<%@ Page Title="" Language="C#" MasterPageFile="~/system/templates2/browser.master" AutoEventWireup="true" %>
<%@ MasterType VirtualPath="~/system/templates2/browser.master" %>

Baidaly
Jul 12, 2013, 10:31 PM
Try to add IDMode attribute:



<script runat="server">
[DirectMethod(IDMode = DirectMethodProxyIDMode.ID)]
public string TEST()
{
Ext.Net.MultiSelect t = new MultiSelect();
Ext.Net.Panel p = new Ext.Net.Panel();
p.Add(t);
return p.ToScript();
}
</script>

amitpareek
Jul 13, 2013, 8:15 PM
Hi Baidaly,
Did you try this at your end? It does'nt work. I just tried. Please try it your end. Are you able to reproduce the error?

Baidaly
Jul 14, 2013, 1:45 AM
Yes, I was able to reproduce your issue. And I've called this methid using this code
DM.TEST()

Try to modify your DirectMethod:


[DirectMethod(IDMode = DirectMethodProxyIDMode.ID)]
public void TEST()
{
X.Msg.Alert("Title", "Test").Show();
}

amitpareek
Jul 14, 2013, 6:40 AM
Tried. Does not work.

Daniil
Jul 15, 2013, 6:10 AM
Thank you for a simplified test case. We do appreciate it.

A note regarding this step.


2) Call DM.Test() from the JS console.


Since you are writing uppercase

[DirectMethod]
public string TEST()
a JavaScript call should be also uppercase.

DM.TEST()

Regarding the rest things.

This setting should be by default:

[DirectMethod(IDMode = DirectMethodProxyIDMode.ID)]

public void TEST()


and it causes that the DirectMethod is rendered this way.

Ext.ns("DM");
Ext.apply(DM, {
ctl00: {
TEST: function (config) {
return Ext.net.DirectMethod.request("TEST", Ext.applyIf(config || {}, {
control: "ctl00"
}));
}
}
});
where the "ctl00" is a master page's ID.

So, you can call it:

DM.ctl00.TEST();

Though, I guess you don't need that "ctl00" stuff, then you should use DirectMethodProxyIDMode.None.

[DirectMethod(IDMode = DirectMethodProxyIDMode.None)]
public string TEST()

Then you can call it:

DM.TEST();

I just tested and it works with your test case.