Sharing knowledge in Project Portfolio Innovation Management (PPIM) and various Technology.
Thursday, November 5, 2009
Memory Profiler.
download: http://memprofiler.com/
Wednesday, October 28, 2009
Health monitoring
This is nice feature in the dotnet frame work 3.5
it will automatically write the event log, When you will not handle the exception in the application,
<system.web>
<healthMonitoring enabled="true"></healthMonitoring>
</system.web>
Thursday, October 22, 2009
how to restrict back button using asp.net.
we shouldn't load the page again when we click on the back button.
Below code it will hide the back button. This is also one of the security leavl have to
follow in the transaction pages.
Response.Buffer = true;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Friday, August 21, 2009
Asp DataGrid with Editable cell with out Postback using Javascript
Sunday, June 8, 2008
Adding rows in DataGrid
DataRow dr = dtg.NewRow();
dr["Item_ID"]="ItemID";
dr["Item_Name"]="Item Name";
dr["Item_Desc"]="Item Description";
dr["Item_Amount"]="$15.65";
dtg.Rows.Add(dr);
DataGrid1.DataSource = dtg;
It will work for windows.
If you use DataGrid in ASP then you will have to keep DataTable in Session:
DataTable dtg = new DataTable();
if (Session["SampleDataTable"]==null)
{
DataColumn dc;
dc = new DataColumn("Item_ID",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Name",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Desc",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Amount",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
}
else {dtg = (DataTable) Session["SampleDataTable"];}
DataRow dr = dtg.NewRow();
dr["Item_ID"]="ItemID";
dr["Item_Name"]="Item Name";
dr["Item_Desc"]="Item Description";
dr["Item_Amount"]="$15.35;
dtg.Rows.Add(dr);
DataGrid1.DataSource=dtg;
DataGrid1.PageSize+=1;
DataGrid1.DataBind();
Session["SampleDataTable"]=dtg;
Monday, April 7, 2008
ASP.NET 2.0 MultiView Control
<asp:MultiView ID="MultiView1" runat="server" >
<asp:View ID="View1" runat="server">This is one section where you can have a set of controls / contents<asp:View>
<asp:View ID="View2" runat="server">This is another section where you can have a different set of controls / contents<asp:View>
</asp:MultiView>
Now, to show the different tabs based on different events, we just need to set the following code:-
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}
"goto" Using Dotnet framework 2.0
{
Response.Write("Testing Goto");
goto Testing;
Testing:
Response.Write("Testing Goto in for loop");
}
output
Testing GotoTesting Goto in for loop
Monday, February 25, 2008
Encryption connectionstring .NET Framework 2.0 using Tool
Configuration File Encryption
In the .NET Framework 2.0, developers will be able to encrypt sensitive parts of the web.config file (if containing password or keys, for instance) using the aspnet_regiis utility. The decryption is done transparently.
The DPAPI protected configuration provider supports machine-level and user-level stores for key storage. The choice of store depends largely on whether or not the application shares state with other applications and whether or not sensitive data must be kept private for each application.
If the application is deployed in the Web farm scenario, developers should use RSAProtectedConfigurationProvider to leverage the ease with which RSA keys can be exported on multiple systems. It uses RSA public key cryptography to provide data confidentiality.
The following example encrypts the connection string section using the tool aspnet_regiis:
try out this...
aspnet_regiis.exe -pef "connectionStrings" C:\VirtualDirectory\Path
URL Mapping in asp.net 2.0
URL Mapping is a mechanism by which you can change the displayed url in address bar.
Example
Step1: Add Mapping URL in web.config file.<system.web>
<urlMappings enabled="true">
<add url="~/Department.aspx" mappedUrl=" oldforms/frmDept.aspx"/>
<add url="~/Employee.aspx" mappedUrl=" oldforms/frmEmployee.aspx"/>
<add url="~/Product.aspx" mappedUrl="& gt;
</urlMappings></system.web>
Step2: Change the URL in .aspx file
<a href="Department.aspx">Department</a><br />
<a href="Product.aspx">Product</a><br />
<a href="Employee.aspx">Employee</a>
Wednesday, January 16, 2008
Datatable Load option in Dotnet Framework 2.0
Definition
Using datatable.load you can load the sqldatareader value directly
Example
DataTable dt = new DataTable();
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection myconn = new SqlConnection(connectionstring);
SqlCommand mycomm = new SqlCommand("select * from FA_contactdetails", myconn);
myconn.Open();
SqlDataReader sqldataread = mycomm.ExecuteReader();
dt.Load(sqldataread);////
myconn.Close();
dggrid.DataSource = dt;
dggrid.DataBind();
Friday, January 4, 2008
Wednesday, January 2, 2008
Thursday, December 13, 2007
Sending Email using "System.Net.Mail"
void Page_Load()
{
//SmtpClient client = new SmtpClient();
//client.Host = "localhost";
//client.Port = 25;
//client.Send("steve@somewhere", "bob@somewhere.com", "Let's eat lunch!", "Lunch at the Steak House?");
}
Wednesday, October 17, 2007
Connection Pooling in ASP.NET
If all connections in the pool are busy and the maximum pool size has not been reached, then new connection is created and added to the pool. When the pool reaches its maximum size all new connection requests are being queued up until a connection in the pool becomes available or the connection attempt times out.
These are four parameters that control most of the connection pooling behavior
Max Pool Size - the maximum size of your connection pool. Default is 100
Min Pool Size - initial number of connections which will be added to the pool upon its creation. Default is zero
Connect Timeout - controls the wait period in seconds when a new connection is requested, if this timeout expires, an exception will be thrown. Default is 15 seconds.
Pooling - controls if your connection pooling on or off. Default as you may've guessed is true. Read on to see when you may use Pooling=false setting.
eg.
connstring="server=myserver;database;abcdefg;Min pool size=5;Max pool size=100;connection timeout=15;pooling=yes"
Most of the Connection problems are because of Connection Leaks
SqlConnection conn=new SqlConnection(constring);
conn.Open();
//do some thing
conn.Close();
while executing the functionality if Exception occurences, then for sure connection wont be closed , to close connection explicitly .. the simple way is ..
SqlConnection conn=new SqlConnection(constring);
try{
conn.Open();
//do some thing
}
finally()
{
conn.Close();
Wednesday, October 10, 2007
Security
when the application uses windows authentication। Asp।Net checks the project's web।config authorization list to see which network users are allowed to access the application. The asterstick(*) and question mark(?) characters have some special meaning in the autorization.
* Charatcter indicates all users
? character indicates unauthenticated users.
Example:
Monday, October 8, 2007
How to create an array of Web Controls
TextBox[] textboxes = new TextBox[5];
for (int i=0; i<5; i++)
{
textboxes[i] = new TextBox();
textboxes[i].ID = "TextBox" + i;
textboxes[i].AutoPostBack = true;
PlaceHolder1.Controls.Add(textboxes[i]);
}
Clear Textbox
foreach (Control ctl in Page.Controls[1].Controls )
{
TextBox tb = ctl as TextBox;
if (tb!=null)
{
tb.Text = "" ;
}
}
Config files
In web.config with in appsetting you have to write the connection string..
Sunday, September 23, 2007
HTML enhancements in ASP.Net 2.0 - PART 2
PART 1 of this article dealt with accessing head tag in codebehind. This part will deal with some more additional enhancements in 2.0 that is really useful.
Accessing <link tag&rt; :
The link tag is useful to register a CSS file with our Webpage. It can be accessed in codebehind or can be added through codebehind by the following code.
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "StyleSheet.css";
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(cssLink);
This will inject a <link&rt; in the html output inside the tag.
<link href="StyleSheet.css" rel="stylesheet" type="text/css" /&rt;
Accessing <Meta&rt; tag :
Meta tags can be used to construct search engine friendly websites, can be used to refresh page and many more. In 2.0 we can achieve this from codebehind through which it gives
the capability to add in runtime.
The following code will do it,
HtmlHead head = (HtmlHead)Page.Header;
HtmlMeta metasearch1 = new HtmlMeta();
HtmlMeta metasearch2 = new HtmlMeta();
metasearch1.Name = "descriptions";
metasearch1.Content = "my personal site";
head.Controls.Add(metasearch1);
metasearch2.Name = "keywords";
metasearch2.Content = "ASP.Net,C#,SQL";
head.Controls.Add(metasearch2);
HtmlMeta metarefresh = new HtmlMeta();
metarefresh.HttpEquiv = "refresh";
metarefresh.Content = "5";
head.Controls.Add(metarefresh);
The following html tag will be injected in the HTML output.
Adding clientside Reset button:
Some time we will need to reset the webpage in clientside which in 2.0 can be done dynamically or in codebehind. The following code will will add a reset input element in the output html.
HtmlInputReset reset = new HtmlInputReset();
reset.ID = "ResetButton";
reset.Value = "Reset";
PlaceHolder1.Controls.Add(reset);
The above code will add a reset tag like below,
<input name="ResetButton" type="reset" id="ResetButton" value="Reset" />
This class is new in 2.0 while this also can be achieved thro HtmlInputButton class in 1.x.