2012-05-11 47 views
1

形式開始:ASP提交按鈕的onclick/_doPostBack

<% using (Html.BeginForm("Index", "recordssbook", FormMethod.Post, new { id = "SubmitForm" })) 
    { %> 

提交按鈕,我想驗證(有相同的形式等提交按鈕):

<div><input type="submit" value="Delete Selected" id ="DeleteButton" name="DeleteButton" onclick="deleteRecordsDialog();"/></div> 

js中的確認對話框中的按鈕會自動返回false:

function deleteRecordsDialog() { 
    var returnThis; 
    var numRecords = selectedRecordsArr.length; 
    document.getElementById("popupContainer"); 
    var html = "" 
    html= html + '<table>'; 
    html= html + '<tr>'; 
    html= html + '<td class="warning-icon-cell"></td>'; 
    html= html + '<td style="padding-left: 5px;">'; 
    if (numAddresses == 1) { 
     html = html + '<p>You have chosen to delete a record.</p>'; 
    } 
    else { 
     html = html + '<p>You have chosen to delete ' + numRecords + ' records.</p>'; 
    } 
    html= html + '<p>Are you sure you wish to proceed?</p>'; 
    html= html + '</td>'; 
    html= html + '</tr>'; 
    html = html + '</table>'; 
    if (numAddresses == 1) { 
     html = html + '<div><input type="button" value="Yes, Delete Contact" style="width: 160px; onclick="document.DSubmitForm.HDeleteButton.submit(); CloseDialog();"/>&nbsp;&nbsp;<input type="button" value="Cancel" onclick="CloseDialog();"/></div>'; 
    } 
    else { 
     html = html + '<div><input type="submit" value="Yes, Delete Contact(s)" style="width: 160px; onclick="document.DSubmitForm.HDeleteButton.submit(); CloseDialog();"/>&nbsp;&nbsp;<input type="button" value="Cancel" onclick="CloseDialog();"/></div>'; 
    } 
    html = html + '</div>'; 
    html = html + '</div>'; 
    html = html + '</div>'; 
    html = html + '</div>'; 
    OpenDialog(html, 350, 180, false, "Delete Contact") 
    return false; 
} 

我的問題:

  1. 即使的onclick返回false提交表單: 我可以將輸入類型更改爲按鈕,而不是提交,這應該工作,如果我能得到的擬提交工作
  2. is _doPostBack提交表單的另一種方式是:從我的谷歌搜索我認爲這應該模擬提交,但當我提交按鈕一個常規的按鈕,如1號所述點擊「是,刪除記錄」不要提交表格。
  3. 我有多個提交按鈕,這使得這更復雜
  4. 我不能使用jQuery的易.dialog

如果有人能幫助我在得到這個工作,我將不勝感激!

謝謝!

編輯 所以html的記錄列表中的按鈕,可以查詢基於信件,添加記錄,刪除記錄和編輯記錄。所有這些按鈕都以相同的形式提交按鈕。

<td><input type="submit" value="ABC" name="SubmitButton"/></td> 
<td><input type="submit" value="DEF" name="SubmitButton" /></td> 
<td><input type="submit" value="GHI" name="SubmitButton" /></td> 
<td><input type="submit" value="JKL" name="SubmitButton"/></td> 
<td><input type="submit" value="MNO" name="SubmitButton"/></td> 
<td><input type="submit" value="PQRS" name="SubmitButton" /></td> 
<td><input type="submit" value="TUV" name="SubmitButton"/></td> 
<td><input type="submit" value="WXYZ" name="SubmitButton" /></td> 
<div><input type="button" value="Add Contact" id="addAddress" onclick="AddAddresDialog()" /></div> 
<div><input type="button" value="View &amp; Edit Selected" id="EditButton" name="EditButton" onclick="updateAddressDialog()"/></div> 
<div><input type="submit" value="Delete Selected" id ="DeleteButton" name="SubmitButton" /></div> 

我只想添加確認對話框到被點擊的刪除按鈕。我想使用一個自定義對話窗口來確認它,這個對話窗口是站點主站上的一個div,通過放置在覆蓋在deleteRecordsDialog()中創建的整個屏幕的掩碼頂部而顯示爲彈出窗口。

我想要做的是將刪除任務(id =「DeleteButton)的提交按鈕更改爲一個常規按鈕,它只是打開由deleteRecordsDialog()創建的對話框,而不是現在提交的表單提交。 ,刪除聯繫人「按鈕應該執行提交表單的任務,提交值爲」刪除選定「,就像提交按鈕現在一樣。

+0

我添加了整個腳本。讓我知道是否需要其他任何東西。我正在使用MVC3 asp.net。 ASP的經典之作一定是從stackoverflow自動更正,對不起!本質上,我需要從site.master的div中形成的自定義彈出對話框的記錄頁上提交表單。 – user1329307

回答

1

很難真正理解你是什麼試圖沒有你的HTML。但是,你可以嘗試以下操作:

HTML

<div> 
    <input type="submit" value="Delete Selected" id ="DeleteButton" name="DeleteButton" onclick="deleteRecordsDialog();"/> 
    <input type="button" id ="DeleteButtonSubmit" name="DeleteButtonSubmit" style="display:none;" /> 
</div> 

Javscript

要爲模式創建按鈕:

html = html + '<div><input type="button" value="Yes, Delete Contact(s)" style="width: 160px; onclick="deleteContact();"/>&nbsp;&nbsp;<input type="button" value="Cancel" onclick="CloseDialog();"/></div>'; 

功能後刪除確認:

function deleteContact() 
{ 
    document.getElementById('DeleteButtonSubmit').click(); 
} 

此功能將點擊用戶最初點擊按鈕下方的隱藏按鈕。如果您正確設置此按鈕,表單應提交您所需的所有信息。

+0

如果我這樣做,我不能讓它提交表單並實際刪除記錄。如果我將其更改爲按鈕,我的自定義對話框會彈出,但問題是我無法使用「是」按鈕來使用「刪除所選參數」來模擬表單提交。 – user1329307

+0

但模式中的按鈕將提交表單不是嗎?這就是你的代碼似乎表明的。 –

+0

這是不工作的部分 – user1329307