from http://www.codersource.net/asp_net_simple_tips.html
1.Smart navigation
To turn on this little-known feature, simply set the smartNavigation property of your ASPX page to True. You can also apply the property to all project pages, by adding the
<--configuration system.web pages smartNavigation="true"/ /system.web /configuration -->
2.Stopping Your User from Right-Clicking
3.Creating Images Dynamically
Here's the code:
Bitmap objBitmap = new Bitmap(120, 30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue), 0, 0, 120, 30);
objGraphics.FillEllipse(new SolidBrush(Color.Blue), 3, 9, 10, 10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow), 4, 10, 8, 8);
objGraphics.DrawString("Drawing", new Font("Tahoma", 8), new SolidBrush(Color.Green), 16, 8);
Response.Clear();
Response.ContentType = "image/jpeg";
objBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
objGraphics.Dispose();
objBitmap.Dispose();
You can put it inside any event you want.
4.Clear All The Textbox Values (Reset Function)
Control myForm = Page.FindControl("Form1");
foreach (Control ctl in myForm.Controls)
if(ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
((TextBox)ctl).Text = "";
Server.Transfer("YourPageName.aspx")
5.Pressing Enter key
Page.RegisterHiddenField("__EVENTTARGET", "button1")
Then, change 'button1' to the ID of your particular button. Understand, of course, if your cursor is inside of a MultiLine textbox, the default action of the enter key is to create a new line in the textbox, so, if this basically works anywhere outside of that scenario.
6.ASP.Net Server Controls Not Showing on pages
It's possible that ASP.Net is not registered correctly on your system.Try running aspnet_regiis from the command prompt
.
Here's the default location:
C:\WINNT\Microsoft.NET\Framework\<
Windows Server 2003, you must use aspnet_regiis -i -enable. This is because of the "Web Service Extensions" feature in IIS 6
7.Where To Store Database Connection
Let's say you have a database connection (or several) that you will be using over and over. Yes, you can manually copy/type it in on every ASP.Net page - BUT - an easier way is to store it in the Web.Config file (formerly config.web) and then refer to it in the code.
In Web.Config, you would add a key to the AppSettings Section:
appSettings>
add key="MyDBConnection" value="server=YourServer;uid=Username;pwd=Password;database=DBName" />
for OleDb - use Absolute Path - Not Server.MapPath:
add key="NWOleDB" value= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\data\northwind.mdb;" />
Then, in your ASP.Net application - just refer to it like this:
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"));