目前分類:ASP.NET (6)

瀏覽方式: 標題列表 簡短摘要

概述

.NET Framework有兩個主要組件:

文章標籤

Jimmy 發表在 痞客邦 留言(0) 人氣()

System.Web.HttpContext.Current.Request.UserLanguages

這個方法應該可以取得使用者端瀏覽器設定的語系,給您參考。

文章標籤

Jimmy 發表在 痞客邦 留言(0) 人氣()

想要抓取動態產生的控制項的值,要利用到識別的 ID 所以在建立控制項的時候就要指定給它,要使用的時候使用父容器的 FindControl 方法找出控制項

protected void Page_Load(object sender, EventArgs e) 
{
    if (IsPostBack) {
         if (   this.ViewState["TextBoxAdded"] != null 
             && (bool)this.ViewState["TextBoxAdded"] == true) 
         {
             AddTextBox();
         }
    }
}

//動態新增控制項
private void AddTextBox() 
{
    PlaceHolder1.Controls.Clear(); //先清除所有子控制項
    TextBox textbox = new TextBox();
    textbox.ID = "DynBox1";//重點是要給他一個ID
    PlaceHolder1.Controls.Add(textbox);
    this.ViewState["TextBoxAdded"] = true;
}

//事件觸發動態新增控制項
protected void Button1_Click(object sender, EventArgs e) 
{
    AddTextBox();
}

//取值出來
protected void Button2_Click(object sender, EventArgs e) 
{
    TextBox tmpbox = PlaceHolder1.FindControl("DynBox1") as TextBox;
    Label1.Text = tmpbox.Text;
}

延伸應用(產生多個TextBox):

Jimmy 發表在 痞客邦 留言(1) 人氣()

由於使用者太習慣輸入完資料時,就按Enter鍵送出。

protected void Page_Load(object sender, EventArgs e)
{
    //註冊JS
    this.txt1.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.Page.ClientScript.GetPostBackEventReference(this.btnTest1, "") + "}");
    this.txt2.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.Page.ClientScript.GetPostBackEventReference(this.btnTest2, "") + "}");
}

這裡要注意一下,必須把Button的UseSubmitBehavior屬性設定為false,這樣這Button的Type則為button,否則 預設為submit

文章標籤

Jimmy 發表在 痞客邦 留言(0) 人氣()

ASP.NET 的 LinkButton本身沒有 target屬性,所以先用以下的方式解決:

先創一個Page(open.aspx),放置一個名為LinkButton1的LinkButton元件

文章標籤

Jimmy 發表在 痞客邦 留言(1) 人氣()

//方法一
Response.Redirect(Request.Url.ToString());
 
//方法二
Response.Write( "<script type=\"javascript\">window.location.href=document.URL;</script>");

//方法三
Response.AddHeader("Refresh", "0");

//方法四
Response.Write( "<script type=\"javascript\">window.location=window.location</script>" );
 

JavaScript 刷新頁面的方法:

window.location.reload()  » 刷新當下的頁面 .

文章標籤

Jimmy 發表在 痞客邦 留言(0) 人氣()