Hi friendz,
In my last project i faced Display dynamic images as per some criteria in a grid. Here i'm sharing the code
Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script runat="server">
public string GetImage(object status)
{
if (status != null)
{
int s = int.Parse(status.ToString());
if (s == 1) return "~/img/yes.jpg";
else if (s == 0) return "~/img/no.gif";
return "~/img/na.gif";
}
return "~/img/na.gif";
}
</script>
</head>
<body>
<form id="form1" runat="server">
######## grid Starts here #########
Item templete
<asp:Image ID="ImportantImage" runat="server" ImageUrl='<%# this.GetImage(Eval("status")) %>' /><br />
######## grid Ends here #########
</form>
</body>
</html>
Have a nice day... 'N happy Coding :)
In this blog i'm posting some Asp.net,Sql Server,Jquery,HTML-5,sqlite,C#,JavaScript scripts and sample codes that i found and created by me or my friends with a mind that it Save/ Help our ass some ways...
Thursday, August 5, 2010
FileUpload Javascript Validation
Hi friends,
It's better to avoid validation through server side even we can do through client side.
this code is for fileupload validation . It wil accept only ".xls", ".xlsx", ".XLS",".XLSX"
Fileuploader Id is FileUpload1
Code
<script type="text/javascript"> function CheckFileExtension() {
var ctrlUpload = document.getElementById('<%=FileUpload1.ClientID%>'); //Does the user browse or select a file or not.
if (ctrlUpload.value == '') {alert("Select a file first!");ctrlUpload.focus();return false;} //Extension List for validation. Add your required extension here with comma separator.
var extensionList = new Array(".xls", ".xlsx", ".XLS", ".XLSX"); //Get Selected file extension
var extension = ctrlUpload.value.slice(ctrlUpload.value.indexOf(".")).toLowerCase(); //Check file extension with your required extension list.
for (var i = 0; i < extensionList.length; i++) { if (extensionList[i] == extension) return true; } alert("You can only upload an Excel File Type i.e.\n" + extensionList.join(" or\n")); ctrlUpload.focus(); return false;
} </script>
now call the function CheckFileExtension() on button onclientclick event it solved
have a nice day 'n happy coding :)
Wednesday, August 4, 2010
Displaying page load time through javascript
Hi friends,
now it's to show page load time in web-pages and it's very simple
Demo
Sample Code
<head>
<title>Calculating Page Loading Time</title>
<SCRIPT LANGUAGE="JavaScript">
//calculate the time before calling the function in window.onload
beforeload = (new Date()).getTime();
function pageloadingtime()
{
//calculate the current time in afterload
afterload = (new Date()).getTime();
// now use the beforeload and afterload to calculate the seconds
secondes = (afterload-beforeload)/1000;
//Fixing to 2 decimal point
secondes = secondes.toFixed(2);
// If necessary update in window.status
window.status='You Page Load took ' + secondes + ' seconde(s).';
// Place the seconds in the innerHTML to show the results
document.getElementById("loadingtime").innerHTML =
"<font color='red'>(You Page Load took " + secondes + " seconde(s).)</font>";
}
window.onload = pageloadingtime;
</SCRIPT>
</head>
<body >
</body>
</html>
Have a nice day... 'N happy Coding :)
Subscribe to:
Posts (Atom)