⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx

📁 ajax是未来之星
💻 ASPX
📖 第 1 页 / 共 2 页
字号:
  public string Company;
}
	</pre>	
    
    <p>In the <a href="source/DemoMethods.cs.txt">DemoMethods.cs</a> I have two methods, one will return a IPerson or IBoss object:</p>
    
    <pre>
[AjaxPro.AjaxMethod]
public IPerson GetPerson(int id)
{
  if(id == 1)
  {
    IPerson b = new IPerson();

    b.FirstName = "Marc Julian";
    b.FamilyName = "Schwarz";
    b.Age = 3;

    return b;
  }

  IBoss p = new IBoss();

  p.FirstName = "Michael";
  p.FamilyName = "Mustermann";
  p.Age = 28;
  p.Company = "My Company GmbH Co.KG";

  return p;
}
    </pre>
    
    <p>Ok, let us test to get the IPerson object to the client:</p>
    
    <pre>
&lt;script language="javascript"&gt;

var p;
var b;

function doIPersonTest()
{
  var res = AjaxProSample.NamespaceTest.Demo.DemoMethods.GetPerson(1);
	
  p = res.value;	// see DemoMethods.cs, a IPerson object
  alert("IPerson p:\r\n" + p.FirstName + " " + p.FamilyName);
	
  res = <b>AjaxProSample.NamespaceTest.Demo.DemoMethods.GetPerson(2)</b>;
	
  b = res.value;	// see DemoMethods.cs, a IBoss object inherited from IPerson
  alert("IBoss b:\r\n" + b.FirstName + " " + b.FamilyName + "\r\n\r\nIBoss.Company = " + b.Company);
}

&lt;/script&gt;
    </pre>
    
    <p>You can see the the <a href="source/DemoMethods.cs.txt">DemoMethods class</a> has a long namespace that will be used on the client as on the server (as you already know you can change this).</p>
    <p><a href="javascript:void(0);" onclick="doIPersonTest()">Click here</a></p>
    
    <p>Now, we have two objects (JavaScript variable <i>b</i> and <i>p</i>), the first one is a IPerson, the second a IBoss object. Let us check it on the server if it is a IBoss object by passing both of them as an argument to following .NET method:</p>
    
    <pre>
[AjaxPro.AjaxMethod]
public bool IsBoss(IPerson p)
{
	return p.GetType() == typeof(IBoss);
}
    </pre>
    
    <p>On the client we will call this method with the two objects:</p>
    
    <pre>
&lt;script language="javascript"&gt;

alert("Is \"p\" a IBoss object?  " + <b>AjaxProSample.NamespaceTest.Demo.DemoMethods.IsBoss(p).value</b>);
alert("Is \"b\" a IBoss object?  " + <b>AjaxProSample.NamespaceTest.Demo.DemoMethods.IsBoss(b).value</b>);

&lt;/script&gt;
    </pre>
    
    <p><a href="javascript:void(0);" onclick="doIPersonTest2();">Click here</a></p>
    
    <h3>Ajax.NET Professional Token</h3>
    
    <p>To secure the calls made to the server I have added a first way to ensure that the client is a valid client. Therefore Ajax.NET Professional writes a token string to the page:</p>
    
    <pre>
&lt;script type="text/javascript"&gt;<b>AjaxPro.token = "63effaab3affeaa8b981cc6dc41c69";</b>&lt;/script&gt;
    </pre>
    
    <p>This token is submitted by default to the Ajax.NET Professional handler that will check if the token is a valid token. You can configure this in the web.config:</p>
    
	<pre>
&lt;ajaxNet&gt;
  &lt;ajaxSettings&gt;
    &lt;token enabled="true" /&gt;
  &lt;/ajaxSettings&gt;
&lt;/ajaxNet&gt;
	</pre>    
	
	<p>Using Fiddler you can see that the token is submitted in the HTTP header to the server:</p>
	<p><img src="images/fiddler-token.gif"></p>
    
    <h3>Debugg/Trace information</h3>
    
    <p>There is a new variable to enable debug messages. Click on one of the buttons and run a Ajax.NET Professional method again.</p>
    
    <pre>
&lt;script language="javascript"&gt;

MS.Debug.enabled = false;		// true to enable debug messages
MS.Debug.trace = function(s){ alert(s); }

&lt;/script&gt;
    </pre>
    
    <p><a href="javascript:void(0);" onclick="MS.Debug.enabled=true;">Enable</a> <a href="javascript:void(0);" onclick="MS.Debug.enabled=false;">Disable</a></p>
    
    
    <h3>The response object</h3>
    
	<p>The <i>res</i> object you get in the callback functions has following properties:</p>    
	
	<table>
	<tr><td>.url</td><td>the URL of the original request</td></tr>
	<tr><td>.value</td><td>the return value of the Ajax.NET Professional method</td></tr>
	<tr><td>.error</td><td>the exception if there is one</td></tr>
	<tr><td>.responseText</td><td>the JSON string</td></tr>
	<tr><td>.request</td><td>the original request data (see below)</td></tr>
	</table>
	
	<p>The <i>res.request</i> object has following properties:</p>
	
	<table>
	<tr><td>.method</td><td>the method that has been called</td></tr>
	<tr><td>.args</td><td>the original used arguments for this method</td></tr>
	<tr><td>.context</td><td>a context object</td></tr>
	</table>


	<h3>Include Web Services in Ajax.NET Professional</h3>
    
    <p>To include a local web service you have to add following line to the HTML code (WebForm1.aspx):</p>
    
    <pre>
&lt;script language="javascript" src="Service1.asmx?AJAX"&gt;&lt;/script&gt;    
    </pre>
    
    <p>In the web.config you have to add to lines to disable the default Web Service handler and add the new Ajax.NET Professional handler. The new handler will only be used if you call the ASMX file with ?AJAX. Other calls are using the default .NET handler. You do not have to extend the Web Methods with the Ajax.NET method attribute.</p>
    
    <pre>
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;

  [...]

  &lt;system.web&gt;
  
    &lt;httpHandlers&gt;
      &lt;add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" /&gt;
      &lt;remove verb="*" path="*.asmx" /&gt;
      &lt;add verb="*" path="*.asmx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" /&gt;
    &lt;/httpHandlers&gt;
    
  [...]
    </pre>
    
    <p>Web Methods do not need the Ajax.NET method attribute. The WebMethod attribute has similar arguments for session state requirement or cache duration.</p>
    
    <pre>
[WebMethod]
public string HelloWorld(string name)
{
  return "Hello " + name;
}    
    </pre>
    
    </form>
    
	<script>

MS.Debug.enabled = false;		// true to enable debug messages
MS.Debug.trace = function(s){ alert(s); }

function isError(res)
{
	if(res.error)
	{
		alert("Error: " + res.error.Message);
		return true;
	}

	return false;
}

function callback1(res)
{
	if(isError(res)) return;
	
	alert("GetSqlServerInfo (DataSet):\r\n\r\nMyTime = " + res.value.Tables[0].Rows[0].MyTime);
	WebForm1.GetDataSetXml(res.value, callback2);
}

function callback2(res)
{
	if(isError(res)) return;
	
	alert("GetDataSetXml:\r\n\r\n" + res.value);
}

function buildSampleDataSet()
{
	var ds = new System.Data.DataSet("MyDataset");
	
	// create first table
	var dt = new System.Data.DataTable("FirstTable");

	// defining columns
	dt.addColumn("FirstName", "System.String");
	dt.addColumn("Age", "System.Int32");
	dt.addColumn("Birthday", "System.DateTime");

	// adding two sample rows 
	dt.Rows.push({"FirstName":"Hans Werner","Age":20,"Birthday":new Date()});
	dt.Rows.push({"FirstName":"Olaf","Age":333,"Birthday":new Date(1977,4,20)});

	// or add you rows using an object
	var r = new Object();
	r.FirstName = "Michael";
	r.Age = 999;
	r.Birthday = new Date();
	dt.Rows.push(r);

	// add the table to the DataSet
	ds.Tables.push(dt);
	
	return ds;
}

function timeTest()
{
	alert("This is the time on the web server using your local time zone: \r\n\t" + AjaxProSample.NamespaceTest.Demo.DemoMethods.GetServerTime().value);
	
	var d = new Date();
	alert("This is your local time (JavaScript):\r\n\t" + d + "\r\n\r\n... and after passing value through web server I get:\r\n\t" + AjaxProSample.NamespaceTest.Demo.DemoMethods.PutServerTime(d).value);
	
	alert("Your local time " + d + " is rendered at the web server using the servers time zone as:\r\n\r\nDateTime.ToString() = " + AjaxProSample.NamespaceTest.Demo.DemoMethods.GetDateStringOnServer(d).value);
}


// WebForm1.GetDataSetXml(buildSampleDataSet(), callback2);
// WebForm1.GetSqlServerInfo(callback1);
// WebForm1.Sleep(new Date(), 10, function(res){alert(res.value[0] + "\r\n" + res.value[1]);});


	</script>
	
	
	
	
	
	<br><br><br>

<p>
<center>

<table cellspacing="5" style="border:1px solid #999999;background-color:white;" width="600">
<tr><td>
<a href="http://www.asp-konferenz.de/" target="_new"><img src="http://www.asp-konferenz.de/images/startRO2005.jpg" border="0"></a>
</td></tr>
<tr><td align="left">
<b>Neues zu ASP.NET 2.0</b><br>
Die finale Version von Visual Studio 2005 und SQL Server 2005 kommt im November 2005.<br>
Bei der 12. ASP konferenz spielt die neue Version von ASP.NET 2.0 die zentrale Rolle. Neue Controls, 70 % weniger Code und eine Menge mehr, das müssen Sie sich einfach ansehen. <br><br>
<b>Highlights</b><br>
<ul><li>AJAX.NET Erfinder und Guru Michael Schwarz zeigt erstmalig wie Microsoft aus AJAX Atlas macht.<br>
<li>Die magische Zahl 7: IIS 7 und IE 7 <br>
<li>Die drei Musketiere, Karsten, Hannes und Christoph MVP's für ASP.NET 
</ul>
<br>
Weitere Infos unter <a href="http://www.asp-konferenz.de" target="_new">www.asp-konferenz.de</a>.
</td></tr>
</table>

</center>
</p>
	
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -