2009-11-11 221 views
0

我使用girdview。和刪除我在每一行使用LinkBut​​ton。現在JavaScript確認不起作用?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if(e.Row.RowType == DataControlRowType.DataRow) 
    { 
     ((LinkButton)e.Row.Cells[12].Controls[0]).Attributes.Add("onClick", 
      "return false;" 
     ); 
    } 
} 

,我希望當點擊因爲OnClick回報falseLink Button發生什麼。對?

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if(e.CommandName=="SIL") 
    { 
     String _id = GridView1.DataKeys[Int32.Parse(e.CommandArgument.ToString())].Values["id"].ToString(); 

     dsodeme_onkayitTableAdapters.odeme_onkayitTableAdapter _todeme = new dsodeme_onkayitTableAdapters.odeme_onkayitTableAdapter(); 
     _todeme.DeleteQueryID(_id); 

     Response.Redirect("musteri_onkayit_odeme_al.aspx?username=" + lbUserName.Text); 
    } 
} 

被調用。 RowCommand正在運行並刪除記錄。

請幫我看看這個問題。我使用Vista Home Premium和IE8。這是問題嗎?

+10

如果您向人們展示JavaScript而不是嘗試生成JavaScript的某些ASP.NET,那麼爲什麼JavaScript不像預期那樣發揮作用要容易得多。 – Quentin 2009-11-11 14:30:43

+1

你在Firefox試過嗎?它有一個錯誤控制檯,可以在這種情況下非常有用。 – 2009-11-11 14:30:56

+2

你必須像代碼 – 2009-11-11 14:34:11

回答

1

好吧,我解決它像這樣; (「onClick」,「if(!confirm('Are you sure?'))event.returnValue = false;」);

它的工作。 謝謝。

0

我覺得Jan必須要做些什麼,是否有可能嘗試添加onClick的實際鏈接不是'cell 12 control 0'?

你應該顯示輸出,我們將能夠找出錯誤。

0

我知道這可能聽起來不像你想要的答案,但如果你知道控制不應該允許刪除,爲什麼不把它隱藏,即隱藏控制。

最終這將實現你正在嘗試做的事情。

+0

嗨,當我在Internet Explorer 8中運行時,確認無效。 但我選擇我的項目右鍵單擊,然後單擊瀏覽...比選擇內部Web瀏覽器。它在內部Web瀏覽器中是非常好的工作。但IE8不起作用conrim? SO是什麼問題? – atromgame 2009-11-11 15:16:19

1

相反的:

((LinkButton)e.Row.Cells[12].Controls[0]).Attributes.Add("onClick", 
      "return false;" 
     ); 

嘗試:

((LinkButton)e.Row.Cells[12].Controls[0]).OnClientClick = "return false;"; 
+0

我嘗試過,但不能再次工作。 – atromgame 2009-11-12 08:27:35