[ASPNET]ASPNET Miscellanea

1. Query String.
Client URL:
http://localhost:8088/TableTopic/Post.aspx?id=12345678&name=andrewzhu
Server Side:

public partial class Post : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
        if (IsPostBack)
            return;
        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)
        return;
    try {
        string fileName = Path.GetFileName(fileUpload.FileName);
        fileUpload.SaveAs(Server.MapPath("~/App_Data/Pictures/") + fileName);
        statusLabel.Text = "file saved";
    } catch (Exception) {           
        throw;
    }
}

4. Separate page with a vertical line:

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

5.IHttpHandler.IsReusable
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
http://forums.asp.net/t/932513.aspx/2/10

7. Page close event

            window.onbeforeunload = function () {
                $.post("http://path",
                       { para:value,para2:value2 },
                       function (data) {
 
                       });
            }

8.Get connection string from web.config file

Connection string in web.config/app.config file

<configuration>
  <connectionStrings>
    <add name="PFAMsdnTechnet" 
         connectionString="Server=Server;Database=Database;Trusted_Connection=True;" 
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
...

Code in c#

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

To be continue。。。

 

 

blog comments powered by Disqus