pontoNETpt
A comunidade PontoNetPT está direccionada a todos os programadores que trabalhem com a plataforma .NET.
Using Ajax.NET under SharePoint
Raul Ribeiro

Syndication

News



  • <!-- Search Google --> <form method="get" action="http://www.google.com/custom" target="_top">
    Google
    <input type="text" name="q" size="5" maxlength="255" value=""></input> <input type="submit" name="sa" value="Go"></input> <input type="hidden" name="client" value="pub-9627805681617022"></input> <input type="hidden" name="forid" value="1"></input> <input type="hidden" name="ie" value="ISO-8859-1"></input> <input type="hidden" name="oe" value="ISO-8859-1"></input> <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input> <input type="hidden" name="hl" value="en"></input>
    </form> <!-- Search Google -->

Retirado de :
Angus Logan

I’m having a play with Ajax.NET because I have some somewhat unique requirements from an application which is delivered under SharePoint.

The requirement is that a process may take 1 hour to complete and the process progress is being stored in a database which must be queried.

So what my plans to do are create a Web Part which looks in the DB for these processes and refresh and image and the UI to display progress – but all without a page refresh.

Ajax.NET is the perfect solution.

When I put the CSharpSample under /_layouts/ and make the initial call:

Ajax.Utility.RegisterTypeForAjax(typeof(WebUserControl1));

I get a cast exception.

Message: Specified cast is not valid

StackTrace: at Ajax.Utility.RegisterCommonAjax() at Ajax.Utility.RegisterTypeForAjax(Type t) at CSharpSample.WebUserControl1.Page_Load(Object sender, EventArgs e) in c:\program files\common files\microsoft shared\web server extensions\60\template\layouts\csharpsample\webusercontrol1.ascx.cs:line 20

The way around this is – don’t make the RegisterTypeForAjax  call!

So you need to manually include the Ajax.NET client side references (bolded below)

Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="CSharpSample.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="CSharpSample.WebUserControl1"TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

<script type="text/javascript" src="/_layouts/CSharpSample/csharpwrapper/common.ashx">/B>script>

<script type="text/javascript" src="/_layouts/CSharpSample/csharpwrapper/CSharpSample.WebUserControl1,CSharpSample.ashx">/B>script>

 

<scriptlanguage="javascript">

function GetTime()

{

      // Make the client side to server side call

      var res = WebUserControl1.GetPercentageComplete();

     

      // Get the value and set the width of the image      

      document.getElementById('progress1').width=res.value;

 

      // TODO: Handle the 100% complete response (hide the table)   

 

      // Repeat the call every 1 second

      setTimeout('GetTime()', 1000);

}

FONT color=maroon>script>

<tablewidth="100"style="border: solid 1px black;" cellpadding="0" cellspacing="0">

      <tr>

            <td><img src="/_layouts/CSharpSample/images/blackpixel.gif" height="15" width="0" id="progress1">/FONT>td>

      /FONT>tr>

FONT color=maroon>table>

The code behind then looks like:

[Ajax.AjaxMethod]

public int GetPercentageComplete()

{

      // Go get the Percentage complete (right now just seconds)

      return(System.DateTime.Now.Second);

}

 

Other than that – Ajax.NET looks awesome.


Posted 11-7-2005 11:47 por Raul Ribeiro
Filed under:

Add a Comment

(requerido)  
(opcional)
(requerido)  
Remember Me?
If you can't read this number refresh your screen
Enter the numbers above:  
Powered by Community Server (Commercial Edition), by Telligent Systems