<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private string[] controls = { "ListView", "GridView", "DetailsView", "FormView", "LinqDataSource", "EntityDataSource" };
protected void Page_Load(object sender, System.EventArgs e) {
if(!this.IsPostBack)
{
Label1.Text = "String array created successfully!<br />Array elements:<br /><br />";
foreach (string element in controls)
{
Label1.Text += element + "<br />";
}
}
}
protected void Button1_Click(object sender, System.EventArgs e)
{
Label2.Text = "Array [2] Index Value: " + controls[2];
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to get string array specific index position value in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">asp.net array example:<br />String Array Specific Index Positin Value</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="HotPink"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Font-Bold="true"
Text="Get Array [2] Value"
ForeColor="SeaGreen"
/>
</div>
</form>
</body>
</html>
Thursday, 29 September 2011
How to get string array specific index position value in asp.net
How to get (search, find) array index position by array element value in asp.net(Array.IndexOf)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private string[] controls = { "SqlDataSource", "AccessDataSource", "ObjectDataSource", "XmlDataSource", "LinqDataSource", "EntityDataSource", "SiteMapDataSource" };
protected void Page_Load(object sender, System.EventArgs e) {
if(!this.IsPostBack)
{
Label1.Text = "String array created successfully!<br />Array elements:<br /><br />";
foreach (string element in controls)
{
Label1.Text += element + "<br />";
}
}
}
protected void Button1_Click(object sender, System.EventArgs e)
{
int indexOf = Array.IndexOf(controls, "LinqDataSource");
Label2.Text ="We Find [LinqDataSource] At the index position: " + indexOf.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to get (search, find) array index position by array element value in asp.net(Array.IndexOf)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">asp.net Array.IndexOf() example:<br />Search Array Index Number By Element Value</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="SeaGreen"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Font-Bold="true"
Text="Search Array [LinqDataSource] Index Position"
ForeColor="SeaGreen"
/>
</div>
</form>
</body>
</html>
Wednesday, 28 September 2011
asp.net cookie example: how to set expires date time
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e) {
HttpCookie cookie = new HttpCookie("ColorCookie");
cookie["Color"] = "Crimson";
cookie["ColorValue"] = "#DC143C";
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
Label1.Text = "Cookie created successfully and set expire after 1 year";
HttpCookie myCookie = Request.Cookies["ColorCookie"];
if (myCookie != null)
{
string color = myCookie["Color"];
string colorValue = myCookie["ColorValue"];
Label1.Text += "<br /><br />Cookie[ColorCookie] Found and read<br/>";
Label1.Text += "Color: " + color;
Label1.Text += "<br />Value: " + colorValue;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net cookie example: how to set expires date time</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">asp.net Cookie example: set cookie expires</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="Crimson"
Font-Italic="true"
Font-Bold="true"
>
</asp:Label>
</div>
</form>
</body>
</html>
asp.net cookie example: how to use cookie in asp.net
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void page_Load(object sender, System.EventArgs e) {
HttpCookie favoriteColor = Request.Cookies["FavoriteColor"];
if (favoriteColor == null)
{
HttpCookie userCookie = new HttpCookie("FavoriteColor");
userCookie["Name"] = "Jones";
userCookie["Color"] = "Crimson";
userCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(userCookie);
Label1.Text = "Cookie created at: " + DateTime.Now.ToString()+ "<br /><br />";
}
else
{
string name = favoriteColor["Name"];
string color = favoriteColor["Color"];
Label1.Text += "Cookie found and read<br />";
Label1.Text += "Hi " + name + " your favorite Color: " + color;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net cookie example: how to use cookie in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">asp.net cookie: how to use</h2>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="SeaGreen">
</asp:Label>
</div>
</form>
</body>
</html>
asp.net cookie example: how to create a cookie
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e) {
HttpCookie userCookie = new HttpCookie("UserInfo");
userCookie["Country"] = "Italy";
userCookie["City"] = "Rome";
userCookie["Name"] = "Jones";
userCookie.Expires = DateTime.Now.AddDays(3);
Response.Cookies.Add(userCookie);
Label1.Text = "Cookie create successful!<br><br/>";
HttpCookie cookie = Request.Cookies["UserInfo"];
if (cookie != null)
{
string country = cookie["Country"];
string city = cookie["City"];
string name = cookie["Name"];
Label2.Text = "Cookie Found and read<br/>";
Label2.Text += "Name: " + name;
Label2.Text += "<br />Country: " + country;
Label2.Text += "<br />City: " + city;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net cookie example: how to create a cookie</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">asp.net Cookie example: Create a cookie</h2>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="SeaGreen">
</asp:Label>
<asp:Label ID="Label2" runat="server" Font-Size="Large" ForeColor="Crimson">
</asp:Label>
</div>
</form>
</body>
</html>
Subscribe to:
Posts (Atom)







