In Mark Up Page :
<%# GetGreeting(Eval("FullName").ToString()) %>
In code behind :
protected string GetGreeting(string name)
{
if (String.IsNullOrEmpty(name))
{
return "Hello";
}
else
{
return "Hello " + name;
}
}
Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executedServer.MapPath("..") returns the parent directoryServer.MapPath("~") returns the physical path to the root of the applicationServer.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)C:\Inetpub\wwwroot
D:\WebApps\shop
http://www.example.com/shop/products/GetProduct.aspx?id=2342
Server.MapPath(".")1 returns D:\WebApps\shop\productsServer.MapPath("..") returns D:\WebApps\shopServer.MapPath("~") returns D:\WebApps\shopServer.MapPath("/") returns C:\Inetpub\wwwrootServer.MapPath("/shop") returns D:\WebApps\shop/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path.Server.MapPath(null) and Server.MapPath("") will produce this effect too.<head runat="server"> <title>Call JavaScript From CodeBehind</title> <script type="text/javascript"> function alertMe() { alert('Hello'); } </script> </head>In order to call it from code behind, use the following code in your Page_Load
protected void Page_Load(object sender, EventArgs e) { if (!ClientScript.IsStartupScriptRegistered("alert")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alertMe();", true); } }