[Mono-dev] How To: ASP.NET Ajax with Mono (with System.Web.Extensions.dll)

Onur Gumus emperon at gmail.com
Tue Aug 28 16:12:49 EDT 2007


Hello  I managed to run ASP.NET Ajax with Mono.

1-) Check out mcs (you need more than System.Web.Extensions to compile)  svn
co svn://anonsvn.mono-project.com/viewcvs/trunk/mcs/  you might also need
svn://anonsvn.mono-project.com/viewcvs/trunk/mono/   I am not sure if it is
necessary since I already have them in the same dir.

2-) Change to (where ever you checked out)/mcs/class/System.Web.Extensions
directory and run make

3-) Create a new Web Project via Monodevelop or create a Default.aspx file
from command line.

4-) Add your built dll to your project . It resides on (where ever you
checked out)/mcs/class/lib/net_2_0/System.Web.Extensions.dll

5-) Make a Default.aspx file as below:

<%@ Page Language="C#" %>

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
         Label Label1 = (Label)this.FindControl("Label1");
        Label1.Text = "Refreshed at " +
            DateTime.Now.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
    #UpdatePanel1 {
      width:300px; height:100px;
     }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="padding-top: 10px">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <asp:Label ID="Label1" runat="server" Text="Panel
created."></asp:Label><br />
                <asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" />

            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        </div>

    </div>
    </form>
</body>
</html>

6-) Add a Web.config file to your project and fill it as below:

<?xml version="1.0"?>
 <configuration>
  <configSections>
    <sectionGroup name="system.web.extensions"
        type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting"
        type="System.Web.Configuration.ScriptingSectionGroup,
        System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
        PublicKeyToken=31bf3856ad364e35">
          <section name="scriptResourceHandler"
            type="
System.Web.Configuration.ScriptingScriptResourceHandlerSection,
            System.Web.Extensions, Version=1.0.61025.0,
            Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            requirePermission="false"
            allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices"
            type="System.Web.Configuration.ScriptingWebServicesSectionGroup,

            System.Web.Extensions, Version=1.0.61025.0,
            Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="jsonSerialization"
              type="
System.Web.Configuration.ScriptingJsonSerializationSection,
              System.Web.Extensions, Version=1.0.61025.0,
              Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService"
              type="System.Web.Configuration.ScriptingProfileServiceSection,

              System.Web.Extensions, Version=1.0.61025.0,
              Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              requirePermission="false"
              allowDefinition="MachineToApplication" />
          <section name="authenticationService"
              type="
System.Web.Configuration.ScriptingAuthenticationServiceSection,
              System.Web.Extensions, Version=1.0.61025.0,
              Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              requirePermission="false"
              allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>


 <system.web>
  <compilation debug="true" />
  <pages>
    <controls>
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
    </controls>
  </pages>

   <httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
  </httpModules>

  <httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="
System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="
System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="
System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=
1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false"/>
  </httpHandlers>

</system.web>


</configuration>

7-) Run the xsp2 from the same directory and open a browser and type
http://localhost:8080

You should see that the Label is updated in ajax way.

Note that you cannot access the controls in your page without FindControl.
This seems to me a bug in aspx parser of Mono. Since the below code works
well on windows as well but not on mono:

protected void Button1_Click(object sender, EventArgs e)
    {
        // Label Label1 = (Label)this.FindControl("Label1");
        Label1.Text = "Refreshed at " +
            DateTime.Now.ToString();
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070828/9feb74c3/attachment.html 


More information about the Mono-devel-list mailing list