2012-11-22 65 views
0

我有一個簡單的問題。extjs/c#是保存到數據庫

我有一個FormView,一個保存按鈕。點擊按鈕後,它會保存到數據庫。

我已經添加了一個EXT消息框來確認用戶是否想要保存數據。當他在messagebox的yes按鈕上點擊yes時,它應該保存數據。

我找不到在哪裏寫分機的按鈕邏輯。

這裏是我的代碼:

 <asp:FormView ID="myform" runat="server" DataSourceID="mydatasource" DefaultMode="Edit" DataKeyNames="Id" > 

     <EditItemTemplate>            
     <asp:TextBox ID="myText" runat="server" TextMode="MultiLine" ClientIDMode="Static" 
     Text='<%#Bind("xx") %>' />             
     <ext:Button ID="btn_Update" runat="server" AutoPostBack="false" CausesValidation="false" CommandName="Update" Text="Speichern" StyleSpec="float: left; margin-left:10px;">                    <DirectEvents> 
<Click OnEvent="btnUpdateClick"></Click> 
</DirectEvents> 
                   </ext:Button> 



    <script type="text/javascript"> 

    function showResult(btn) 
    { 
      Ext.example.msg('Button Click', 'You clicked the {0} button', btn); 
     }; 
     function showResultText(btn, text) 
     { 
      Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text "{1}".', btn, text); 
     } 

     var showResult = function (btn) { 
      Ext.Msg.notify("Button Click", "You clicked the " + btn + " button"); 
     }; 

     var showResultText = function (btn, text) { 
      Ext.Msg.notify("Button Click", "You clicked the " + btn + 'button and entered the text "' + text + '".'); 
     }; 


</script> 



protected void btnUpdateClick(object sender, DirectEventArgs e) 
     { 
      X.Msg.Confirm("Confirm", "Are you sure you want to save?", new JFunction { Fn = "showResult" }).Show(); 

     } 
+1

請提供一個示例/更改您的問題。消息框無法更新任何內容。所以你不清楚你在問什麼。 – sra

+0

消息框有和沒有按鈕(你想要保存數據),當用戶單擊是時,它應該保存數據,我只是不知道我怎麼能做到這一點,現在我將提供代碼。 – Mark

回答

0

我會建議,而不是佈線對話框的是按鈕執行回發。您應該等待消息框關閉,然後在用戶單擊是時調用回發功能。

例如:

Ext.Msg.prompt('SaveChange', 'Would you like to save the changes?:', function(btn, text){ 
    if (btn == 'yes'){ 
     __doPostBack('btnSubmit','OnClick'); 
    } 
}); 

與您的按鈕的名稱替換btnSubmit按鈕。

雖然上述解決方案將是我推薦的方法,你可以通過做或者,使用jQuery:

$('btnSubmit').trigger('click'); 

來源:http://dev.sencha.com/playpen/docs/output/Ext.MessageBox.html

+0

要點是,我的行動是讓按鈕做回發動作,我不能讓這種事情發生。 – Mark

+0

-1用於混淆jquery和extjs。有沒有需要使用兩個庫 – sra

+0

強烈反對,jquery是如此事實與asp.net它實際上是框架的一部分,我也提供了一個標準的asp.net方法來執行此操作! –

2

我猜你正在尋找這樣的:(可放置在任何演示盒的煎茶API)的

編輯2

我有完全監督你使用Direct。你應該提到這樣的事情。 是否有任何使用DirectEvent的理由?我無法測試,但這個怎麼樣(在包裝功能部件可能是不必要的,但一個正常的ExtJS的處理程序獲得按鈕引用作爲第一個參數)

<form runat="server"> 
     <ext:ResourceManager runat="server" /> 

     <script runat="server"> 
      [DirectMethod] 
      public void SetTimeStamp(string field) 
      { 
       // do your saving 
      } 
     </script> 
     <ext:TextField ID="TextField" runat="server" FieldLabel="Label"/> 
     <ext:Button ID="Button" runat="server" Text="Click Me" Icon="Lightning"> 
      <Listeners> 
       <Click Handler="function() {Ext.Msg.show({title: 'Save?', msg: 'Do you want to save the data?:', buttons: Ext.Msg.YESNO,fn: function(btn){ if(btn == 'yes') {App.direct.SetTimeStamp(#{TextField}.getValue());}}})}" /> 
      </Listeners> 
     </ext:Button> 
</form> 

編輯1只需使用Ext.Ajax.request()

Ext.Msg.show({ 
     title: 'Save?', 
     msg: 'Do you want to save the data?:', 
     buttons: Ext.Msg.YESNO, 
     fn: function(btn, text){ 
       Ext.Ajax.request({ 
       url: 'yourUrl', 
       method: 'POST', 
       params: { 
        // your params 
       }, 
       success: function() { 
        console.log('success'); 
       }, 
       failure: function() { 
        console.log('woops'); 
       } 
      }); 
     } 
}); 

形式示例除去

+0

要點是,我的行動是讓按鈕做一個回發動作,我不能讓這種情況發生。 – Mark

+0

@Mark我做了一個編輯,現在單擊YES後觸發ajax請求 – sra

1

謝謝大家的支持,我找到了解決問題的方法我會把它放在這裏,也許對某個人有用。

首先,按鈕代碼,必須在ASPX按鈕事件Isupload = 「真」

ext:Button ID="btn_Update" runat="server" AutoPostBack="false" CausesValidation="false" 
CommandName="Update" Text="Save" StyleSpec="float: left; margin-left: 10px;" 
AutoScroll="False"> 
<DirectEvents> 
<Click OnEvent="btnUpdateClick" IsUpload="true" AutoDataBind="true"> 
</Click> 
</DirectEvents> 
</ext:Button> 

protected void btnUpdateClick(object sender, DirectEventArgs e) 
{ 
     MessageBoxButtonConfig buttonYes = new MessageBoxButtonConfig(); 
     buttonYes.Text = "Yes"; 
     buttonYes.Handler = "Ext.net.DirectMethods.ClickedYES();"; 

     MessageBoxButtonConfig buttonNo = new MessageBoxButtonConfig(); 
     buttonNo.Text = "NO"; 
     // buttonNo.Handler = "Ext.net.DirectMethods.ClickedNO();"; 

     MessageBoxButtonsConfig yesNoButtons = new MessageBoxButtonsConfig(); 
     yesNoButtons.Yes = buttonYes; 
     yesNoButtons.No = buttonNo; 

     X.Msg.Confirm("Save Changes", "Would you like to Save?", yesNoButtons).Show(); 
} 

最後的是方法,將保存到數據庫:

[DirectMethod] 
public void ClickedYES() 
{ 
     Formview.UpdateItem(false); 
     Formview.DataBind(); 
} 
+0

感謝您分享您的解決方案+1 – sra