2013-05-16 54 views
1

我的下面的代碼工作正常,除非單擊按鈕「繼續」時,它不會發送值爲true。jQuery對話框點擊按鈕時如何通過'True'

<script type="text/javascript"> 
    function EmpDelete(f_name) { 
     $("#fName").text(f_name); 
     $('#dialog').dialog({    
      title: "Delete Employee?",    
      modal: true, 
      width: 500, 
      height: 250,    
      buttons: { 
       "Cancel": function() { 
        $(this).dialog("close"); 
       }, 
       "Continue": function() {      
        $(this).dialog("close"); 
        // return true; 
       }     
      }    
     });       
     return false; 
    };  
</script> 

當imgDelete ImageButton被點擊時,上面的jQuery事件被調用。

e.Row.Cells[iDelete].Controls.Add 
    (new ImageButton 
    { 
     ImageUrl = "Images/database_delete.png", 
     CommandArgument = e.Row.RowIndex.ToString(), 
     CommandName = "Delete", 
     ID = "imgDelete", 
     CssClass = "imgDelete",     
     OnClientClick = "return EmpDelete('" + e.Row.Cells[iFNmae].Text + "');",  
     ClientIDMode = System.Web.UI.ClientIDMode.Static 
    }); 

我怎樣才能讓「繼續」 jQuery的按鈕返回true值,所以我的「RowCommend」事件可以做進一步的處理?

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Delete") 
    { 

    } 
} 

回答

1

我意識到我已經做了類似的事情,回頭看看我的代碼,看看爲什麼我沒有使用我在其他答案中提到的第二個「參數」參數。

在我的情況下,而不是一個GridView,我有一個Repeater。每行中的一個按鈕觸發jQuery UI對話框彈出。但是,即使我有多行,我也只有一個jQuery UI對話框;其內容根據按下哪一行按鈕而改變。我的對話框有表單字段,所以當按下對話框按鈕時,我會調用由GetPostBackEventReference()方法生成的javascript函數。由於對話框窗體中的字段正在提交,因此我不需要指定任何參數。

我的觀點是,你的情況,而不是使用我在其他答案中提到的第二個'參數'參數,你可能只需在你的對話框中創建一個HiddenField。如果您在對話框中提交表單域,那麼您將能夠在RowCommand事件處理程序中捕獲該HiddenField。只需在啓動回發之前將其值設置爲True即可。在你的情況下,我假設你還需要一個隱藏字段來標識哪個員工應該被刪除(某種類型的EmployeeID值)。

1

嘗試尋找到ClientScriptManager.GetPostBackEventReference方法 http://msdn.microsoft.com/en-us/library/ms153112.aspx

請參閱以下職位如何使用它的說明...... asp:Button in jQuery dialog box not firing OnClick event

我沒有用它來傳遞沿着一個CommandArgument,但是方法的第二個參數聲明它是用於'參數'的。您可以嘗試在該參數參數中傳遞True值,並查看是否可以在RowCommand事件處理程序中捕獲它。

0

我解決它通過對jQuery的使用__doPostBack(uniqueID, ''); 「繼續」 按鈕,

在我加入

if (!Page.IsPostBack) 
    { 
     ClientScript.GetPostBackEventReference(gvEmployee, string.Empty); 
    } 

在Page_Load()事件,我打電話給jQuery的對話框Gridview_RowDataBound事件

e.Row.Cells[iDelete].Controls.Add 
      (new ImageButton 
      { 
       ImageUrl = "Images/database_delete.png", 
       CommandArgument = e.Row.RowIndex.ToString(), 
       CommandName = "Delete", 
       ID = "imgEmpDelete" + e.Row.Cells[iID].Text, 
       **OnClientClick = "javascript:return rowAction(this.name)",** 
       ClientIDMode = System.Web.UI.ClientIDMode.Static 
      }); 

希望它可以幫助任何人。

相關問題