String extension in ASP.NET AJAX

This entry is part 8 of 13 in the series ASP.NET Ajax

ASP.NET AJAX client side framework also extends the string type to add support for the .NET like methods.

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Client Side Event in ASP.NET Ajax</title>
<script language="javascript" type="text/javascript">
function pageLoad() {
var string = "w3mentor.com";
alert(string.endsWith("com"));
alert(string.startsWith("w3"));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
ASP.NET AJAX Demo Page
<asp:ScriptManager runat="server" ID="SM1" />
</div>
</form>
</body>
</html>

When you run the above .aspx page, you will get “true” and “true” alert. This alert comes because of ScriptManager that has string extension out of the box which helps us to deal with string in .NET style.

Now remove the ScriptManager and try to keep the pageLoad method in the body load and you shall get a JavaScript error because there is no endsWith or startWith method in the JavaScript.
Apart from Array and String extension, ASP.NET AJAX client side framework also provides other extension like Error type extension, Base type extensions that can be used to develop more robust, user friendly ASP.NET AJAX Application.

Series Navigation«Array extensions in ASP.NET AJAX client side frameworkScriptManager in ASP.NET Ajax»

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.