Monday, January 4, 2010

Sys.StringBuilder Class in Ajax

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax_StringBuilder.aspx.cs" Inherits="Ajax_StringBuilder" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>

<script type="text/javascript">
function buildAString(title){
var headTagStart = "<head>";
var headTagEnd = "</head>";
var titleTagStart = "<title>";
var titleTagEnd = "</title>";

var sb = new Sys.StringBuilder(this._headTagStart);
Sys.Application.add_load(load);
sb.append(titleTagEnd);
sb.append(title);
sb.append(titleTagEnd);
sb.append(headTagEnd);
// Displays: "The result: <head><title>A Title</title></head>"
//alert("The result" + sb.toString());
}

var title = "A Title";
buildAString(title);
function load()
{

}
</script>
<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>

<%
Application.Add("Counter", 1);
Application["Counter"] = (int)Application["Counter"] + 1;
%>
</form>
</body>
</html>

No comments: