Archive for the 'ASP.NET' Category

Cookiless Session State in ASP.NET

July 20, 2008

When each user browse a Page the unique Session  Object is created….Session Object is idendified by unique session Id.
The Session ID is Sent back to the client in the form of cookies.
Some browser does not support cookies.. So that we can set cooliless=true.
For that… the Session ID Sent to the URL QueryString.

To Change the gridview lines color in ASP.NET

July 20, 2008

<asp:DataGrid ID=”DataGrid1″ runat=”server” AutoGenerateColumns=”False”
BorderColor=”Black” BorderStyle=”Solid” BorderWidth=”1px” Width=”300px” PageSize=”7″>
<Columns>
<asp:TemplateColumn ItemStyle-BorderColor=”blue” ItemStyle-BorderStyle=”solid” ItemStyle-BorderWidth=”2px”>
<ItemTemplate>
<center>
<asp:Label ID=”Label1″ runat=”server” Text=’Hello’></asp:Label>
</center>
</ItemTemplate>
<HeaderStyle HorizontalAlign=”Center” />
</asp:TemplateColumn>
<AlternatingItemStyle BackColor=”Gainsboro” BorderColor=”White” />
<HeaderStyle BackColor=”Gray” />
<EditItemStyle BorderColor=”White” />
<ItemStyle BorderColor=”White” />
</asp:DataGrid>

Region Based Default Button in ASP.NET

July 20, 2008

EmailTextBox.Attributes.Add(“onKeyPress”, “javascript:if (event.keyCode == 13) __doPostBack(‘” + LoginButton.UniqueID + “‘,”)”);
Another one Simple Method is use the Panel inside it put the Default Button Focus To It
<asp:Panel ID=”Hi” runat=”server” DefaultButton=”Button1″>
You can also  kept the focus coding at the Form tag itself
<form id=”form1″ runat=”server”  defaultbutton=”Button3″ >

To Send an XML stream to another Page in ASP.NET

July 20, 2008

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Net;
public partial class SendStream : System.Web.UI.Page
{
HttpWebRequest MyRequest;
#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
#region Send_Stream
protected void Button1_Click(object sender, EventArgs e)
{
try
{
using(SqlConnection SQLCon = new SqlConnection(“server=.;database=TEST;user id=sa;password=sa”))
{
SQLCon.Open();
string Str = “SELECT * FROM CATEGORY AS CATEGORY”;
SqlCommand SQLCmd = new SqlCommand(Str, SQLCon);
DataSet Ds = [...]

Using Block inside the void Main in c#.NET,ASP.NET

July 20, 2008

We can’t able to use the using block inside the
public static void main(String args[])
{
using (ReadingFile Rf = new ReadingFile())
{
Rf.ReadFile();
}
}
Like the above usage.Because the System.IDisposible implisitely
called inside the static void main(String args[]) function.

Inner Class,Creating an Instance Of the Class

July 20, 2008

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleExample
{
public class OuterClass
{
public void OuterClassFunction()
{
Console.WriteLine(“I am in Outer Class Function”);
}
//Reinitialize the class
public InnerClass abc()
{
return new InnerClass();
}
public class InnerClass
{
public OuterClass OutC()
{
return new OuterClass();
}
public string PublicInner;
private string privateInner;
public InnerClass()
{
}
public void InnerClassFunction()
{
Console.WriteLine(“I am in InnerClass”);
}
void PrivateFunction_InnerClass()
{
Console.WriteLine(“I am a Private function Of InnerClass”);
}
}
}
}
________________________________________________________________________
For the Above example the Instance are named as abc(),OutC()
To Call an instance  [...]

Variable Passing in C#.Net

July 20, 2008

class PropertiesExplaination
{
void OrdinaryAccessMethod(params int[] Params)
{
Console.WriteLine(Params.Length);
}
static void Main(string[] args)
{
PropertiesExplaination Obj = new PropertiesExplaination();
Obj.a = 1;
Obj.OrdinaryAccessMethod(Obj.a,Obj.a+1,Obj.a+3);
Console.Read();
}
}
For the above Example PropertiesExplaination is a Class Name and  OrdinaryAccessMethod is a sample method.
params-> is a Keyword to Pass a Array of Variables.
For the above example I am passing an array of Integer values to the Method of OrdinaryAccessMethod(Method Name)

Session Time Out Limit

May 6, 2008

Session Default Time Out is 20 minutes
Maximum we can set up to 4,000  years,,,,,
Session.TimeOut=Minutes.
2,147,483,647

Instead of DataBinder.Eval use DataRowView

May 6, 2008

<%# ((DataRowView)Container.DataItem)["name1"] %>
This One  is the  Best One……..While using DataBinder.Eval()
If your Record exeecds than 100 Rows..It Will become a Problem.More duplication Will Occur.

To Change the GridView Lines Color

May 6, 2008

<asp:DataGrid ID=”DataGrid1″ runat=”server” AutoGenerateColumns=”False”
BorderColor=”Black” BorderStyle=”Solid” BorderWidth=”1px” Width=”300px” PageSize=”7″>
<Columns>
<asp:TemplateColumn ItemStyle-BorderColor=”blue” ItemStyle-BorderStyle=”solid” ItemStyle-BorderWidth=”2px”>
<ItemTemplate>
<center>
<asp:Label ID=”Label1″ runat=”server” Text=’Hello’></asp:Label>
</center>
</ItemTemplate>
<HeaderStyle HorizontalAlign=”Center” />
</asp:TemplateColumn>
<AlternatingItemStyle BackColor=”Gainsboro” BorderColor=”White” />
<HeaderStyle BackColor=”Gray” />
<EditItemStyle BorderColor=”White” />
<ItemStyle BorderColor=”White” />
</asp:DataGrid>