global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["OnlineUsers"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
=============================================
Get data in page
lblMessage.Text = DateTime.Now.ToShortDateString();
lblMessage.Text += " " + Application["OnlineUsers"].ToString();
Monday, October 26, 2009
Friday, September 18, 2009
Encript Decript String In Asp.Net
public string Encrypt(string text) // public static string Encrypt(string text)
{
try
{
text = text.Trim();
byte[] encData_byte = new byte[text.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(text);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch
{
throw;
}
// return string.Empty;
}
public string Decrypt(string text) // public static string Decrypt(string text)
{
try
{
text = text.Trim();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(text);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result.Replace("\\","").Replace("\"","");
}
catch
{
throw;
// Handle Exception Here
}
// return string.Empty;
}
Call Encript Decript Finction In Code Behind file:-
string Id = Decrypt(Request["Id"]);
string Id = Encrypt("\"" + Ds.Tables[0].Rows[i]["MaterialID"].ToString() + "\"");
{
try
{
text = text.Trim();
byte[] encData_byte = new byte[text.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(text);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch
{
throw;
}
// return string.Empty;
}
public string Decrypt(string text) // public static string Decrypt(string text)
{
try
{
text = text.Trim();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(text);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result.Replace("\\","").Replace("\"","");
}
catch
{
throw;
// Handle Exception Here
}
// return string.Empty;
}
Call Encript Decript Finction In Code Behind file:-
string Id = Decrypt(Request["Id"]);
string Id = Encrypt("\"" + Ds.Tables[0].Rows[i]["MaterialID"].ToString() + "\"");
To script All the Stored Procedures in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'P'
If the Stored Procedure is created with ENCRYPTION option then you will get the NULL in the definition column.
Similarly,
To script All the Views in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'V'
To script All the Functions in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'FN'
For scripting all Triggers small modification is required, instead of sys.objects I joined the sys.triggers with sys.sql_modules.
To script All the Triggers in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.triggers as O
ON M.object_id = O.object_id
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'P'
If the Stored Procedure is created with ENCRYPTION option then you will get the NULL in the definition column.
Similarly,
To script All the Views in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'V'
To script All the Functions in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'FN'
For scripting all Triggers small modification is required, instead of sys.objects I joined the sys.triggers with sys.sql_modules.
To script All the Triggers in the Database :
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.triggers as O
ON M.object_id = O.object_id
Wednesday, September 16, 2009
Dynamic create table using code behind
Table table = new Table();
for (int j = 1; j < 4; j++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
// Add the control to the TableCell
string Temp = j==1 ? str1 : j==2 ? str2 : j==3 ? str3 : "";
cell.Text = Temp;
row.Controls.Add(cell);
table.Rows.Add(row);
}
this.Page.Controls.Add(table);
for (int j = 1; j < 4; j++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
// Add the control to the TableCell
string Temp = j==1 ? str1 : j==2 ? str2 : j==3 ? str3 : "";
cell.Text = Temp;
row.Controls.Add(cell);
table.Rows.Add(row);
}
this.Page.Controls.Add(table);
Tuesday, September 8, 2009
Encript And Decript String
Encrypting Connection String Code
private string EncryptConnectionString(string connectionString)
{
Byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(connectionString);
string encryptedConnectionString = Convert.ToBase64String(b);
return encryptedConnectionString;
}
Once you got the encrypted connection string you can copy and paste it in the web.config file
<appSettings>
<add key="ConnectionString" value="ZGF0YSBzb3VyY2U9Llx2c2RvdG5ldDtpbml0aWFsIA0KICAgY2F"/>
Decrypting Connection String
private string DecryptConnectionString()
{
Byte[] b = Convert.FromBase64String(ConfigurationSettings.AppSettings["ConnectionString"]);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
}
private string EncryptConnectionString(string connectionString)
{
Byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(connectionString);
string encryptedConnectionString = Convert.ToBase64String(b);
return encryptedConnectionString;
}
Once you got the encrypted connection string you can copy and paste it in the web.config file
<appSettings>
<add key="ConnectionString" value="ZGF0YSBzb3VyY2U9Llx2c2RvdG5ldDtpbml0aWFsIA0KICAgY2F"/>
Decrypting Connection String
private string DecryptConnectionString()
{
Byte[] b = Convert.FromBase64String(ConfigurationSettings.AppSettings["ConnectionString"]);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
}
Sunday, August 30, 2009
Gird view Find result
When you are using paging then you use lines of code for finding the rowindex id
GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = gvr.RowIndex;
When you are doesn't use paging then you ues below code to find the row index record
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection. Use the
// CommandSource property to access the GridView control.
GridView customersGridView = (GridView)e.CommandSource;
GridViewRow row = customersGridView.Rows[index];
// Create a new ListItem object for the customer in the row.
Response.Write(Server.HtmlDecode(row.Cells[1].Text));
GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = gvr.RowIndex;
When you are doesn't use paging then you ues below code to find the row index record
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection. Use the
// CommandSource property to access the GridView control.
GridView customersGridView = (GridView)e.CommandSource;
GridViewRow row = customersGridView.Rows[index];
// Create a new ListItem object for the customer in the row.
Response.Write(Server.HtmlDecode(row.Cells[1].Text));
Monday, August 17, 2009
Data Bind
Binding database record in the your strcture.
<%#DataBinder.Eval(Container.DataItem,"FirstName")%>
<%#Eval("id") %>
<%#Bind("id") %>
<%#DataBinder.Eval(Container.DataItem,"FirstName")%>
<%#Eval("id") %>
<%#Bind("id") %>
Subscribe to:
Posts (Atom)