[ASPNET]ASPNET Miscellanea

1. Query String.
Client URL:
Server Side:

public partial class Post : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
        if (IsPostBack)
        body.Text = this.Request.QueryString["name"];

2. Why do we need <!doctype>
To make sure Web Browser render the page correctly. or make rendering faster.

3. Use ASP.NET FileUpload control.

In aspx page, we add two controls

<asp:FileUpload ID="fileUpload" runat="server" />
<asp:Button ID="uploadButton" runat="server" Text="Upload"
onclick="uploadButton_Click" />

In the behind cs file, add the following code for the upload button click event.

protected void uploadButton_Click(object sender, EventArgs e) {
    if (!fileUpload.HasFile)
    try {
        string fileName = Path.GetFileName(fileUpload.FileName);
        fileUpload.SaveAs(Server.MapPath("~/App_Data/Pictures/") + fileName);
        statusLabel.Text = "file saved";
    } catch (Exception) {           

4. Separate page with a vertical line:

 <table border="0" cellpadding="0" cellspacing="0" width="500">
     <td width="50%" valign="top" align="left">
        <p>The main page content here </p>
     <td width="50%" valign="top" align="left" 
="border-left1px solid cyanpadding5px;">

Set the property to true, if the HttpHandler instance is reusable.  When the http handler needs heavy initailization. we set IsReusable to true to pool the instance. so that this handler can serve request fast.

6.What is AutoEventWireup

7. Page close event

            window.onbeforeunload = function () {
                       { para:value,para2:value2 },
                       function (data) {

8.Get connection string from web.config file

Connection string in web.config/app.config file

    <add name="PFAMsdnTechnet" 

Code in c#

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;

To be continue。。。



blog comments powered by Disqus