2012-02-14 52 views
-2

在我的aspx頁面我有一個按鈕可以在數據庫中保存多個值。彈出按鈕的操作結束

我需要在操作結束時插入一個popuup。

目前的代碼是:

protected void btnSendRequest_Click(object sender, EventArgs e) 
{ 
    var myDbAccess = new DBAccess(); 
    Event newEvent = (Event)Session["NewEvent"]; 

    myDbAccess.SaveEvent(newEvent); 

    // Insert here a PopUp like "Successfully saved!" 

} 

我怎樣才能做到這一點?

路易吉

回答

1

你應該使用ClientScript.RegisterStartupScript打開彈出窗口。

protected void btnSendRequest_Click(object sender, EventArgs e) 
{ 
    var myDbAccess = new DBAccess(); 
    Event newEvent = (Event)Session["NewEvent"]; 

    myDbAccess.SaveEvent(newEvent); 

    // Insert here a PopUp like "Successfully saved!" 
    var popupCode = @"<script>alert ('Javascript block of code executed')</script>"; 
    ClientScript.RegisterClientScriptBlock(this.GetType(),"myKey",popupCode); 

} 

你也可以通過在RegisterClientScriptBlock方法的末尾使用如下

protected void btnSendRequest_Click(object sender, EventArgs e) 
{ 
    var myDbAccess = new DBAccess(); 
    Event newEvent = (Event)Session["NewEvent"]; 

    myDbAccess.SaveEvent(newEvent); 

    // Insert here a PopUp like "Successfully saved!" 
    var popupCode = @"alert ('Javascript block of code executed');"; 
    ClientScript.RegisterClientScriptBlock(this.GetType(),"myKey",popupCode,true); 

} 

注過載的TRUE值刪除您的字符串塊。

嘗試上面的代碼,讓我知道發生了什麼。

+0

它給我這個錯誤: Errore:Sys.WebForms.PageRequestManagerServerErrorException: – Ciupaz 2012-02-14 13:03:51

0

你可以使用這樣的:

string [email protected]"<script language='javascript'></script>"; 
    ClientScriptManager cs = Page.ClientScript; 
    cs.RegisterStartupScript(this.GetType(), "MyScript",Scr, false); 
    cs.RegisterClientScriptBlock(this.GetType(), "My alert", "alert('" Saved Successfully"');", true); 

注意第一RegisterStartupScript具有False的最後一個參數和未來具有True

如需更多幫助: - RegisterClientScript

+0

對不起,這是行不通的。 – Ciupaz 2012-02-14 13:00:41

+0

請參閱編輯的代碼 – Pranav 2012-02-14 13:11:08

+0

嘗試此編輯的代碼,並讓我知道你是否面臨任何問題。 – Pranav 2012-02-14 13:20:58

1

您可以通過這樣做以下:

protected void btnSendRequest_Click(object sender, EventArgs e) 
{ 
    var myDbAccess = new DBAccess(); 
    Event newEvent = (Event)Session["NewEvent"]; 

    myDbAccess.SaveEvent(newEvent); 

    // Insert here a PopUp like "Successfully saved!" 

    string script = "<script type=\"text/javascript\">alert('successfully saved');</script>"; 
    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script); 
} 

我希望這有助於。歡呼:)

0

jquery模型對話框是最好的。你可以很容易地將這與asp.net整合。


public void SomeButton_Click(Object sender, EventArgs e) 
    { 
     string script = "$('#someid').dialog('open');"; 
     ClientScript.RegisterStartupScript(GetType(), "popup", script, true); 
    }