RSS

Create FirendlyUrl from Text

26 May

Aspx File

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
<script src=”js/Utility.js” type=”text/javascript”></script>
<script type=”text/javascript”>

function updateFirendlyUrl() {

if (document.getElementById(‘<%=txtfriendlyUrl.ClientID%>’).value == “”) {
var URL = ParseURL(document.getElementById(“<%=txtPageName.ClientID %>”).value);
if (URL != “”) document.getElementById(‘<%=txtfriendlyUrl.ClientID%>’).value = URL;
}
}

</script>
</head>

<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr><td>
Name:
</td>
<td>
<asp:TextBox ID=”txtPageName” runat=”server”></asp:TextBox>
</td>
</tr>
<tr><td>
Result url:
</td>
<td>
<asp:TextBox ID=”txtfriendlyUrl” runat=”server”></asp:TextBox>
</td>
</tr>
<tr><td colspan=”2″ align=”right”>
<input type=”button” name=”button” id=”button” onclick=”updateFirendlyUrl()” value=”Submit” />
</td></tr>
</table>

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

js File

Utility.js

function ParseURL(URL) {
var title = URL;
/*var idx = title.indexOf(” & “);
while (idx > -1) {
title = title.replace(” & “, “-“);
idx = title.indexOf(” & “);
}
idx = title.indexOf(“&”);
while (idx > -1) {
title = title.replace(“&”, “”);
idx = title.indexOf(“&”);
}
idx = title.indexOf(” “);
while (idx > -1) {
title = title.replace(” “, “-“);
idx = title.indexOf(” “);
}*/
/*
title = title.replace(/ & /g, “-“)
title = title.replace(/&/gi, “”)
title = title.replace(/ /g, “-“)
title = title.replace(/@/gi, “”)
*/
title = title.replace(/&amp;/gi, “”)
title = title.replace(/ /g, “-“)

title = title.replace(/[^a-zA-Z 0-9 -]+/g, ”);

if (title != “”)
return “/” + title + “.aspx”;

}

function GetTitleFromFileName(Control, txtPageName) {
if (Control) {
var arr1 = Control.value.split(“\\”);
var arr2 = arr1[arr1.length – 1].split(“.”);
document.getElementById(txtPageName).value = arr2[0];
}
}

Advertisements
 
Leave a comment

Posted by on May 26, 2011 in Vb.Net

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: