2016-10-04 63 views
1

我在asp.net Usercontrol中有一個RadioButtonList。它包含值「離開」,「可用」。當用戶點擊「離開」時,我應該將信息顯示爲「你確定要離開嗎?」 「確定」和「取消」按鈕。恢復asp.net中RadiobuttonList的以前狀態

當用戶點擊Available/Leave時,下面的事件觸發。

protected void rdlUser_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    if (rdlUser.SelectedIndex == 0) 
    { 
      radWindowManager.RadConfirm("Are you sure you want to take Leave?", "confirmSave" + this.ClientID, 300, 100, null, ""); 
    } 
} 

這是客戶端的JavaScript函數...

function confirmSave<%=this.ClientID%>(arg) { 
    if (arg == true) { 
     $find('<%= FindControl("txtUser").ClientID %>').set_value("User has taken Leave"); 
} 

**如果用戶點擊離開單選框,並單擊在確認消息框中取消,那麼程序應該恢復更改爲「可用「 單選按鈕。我如何在Server/Client端以編程方式選擇「Available」?

編輯:主要目標是重置價值以前的狀態**

回答

0

添加else語句趕上arg==false並設置所需的射頻輸入checked屬性true。見Check a radio button with javascript

+0

我在這裏有一個問題。 RadiobuttonList的Radiobuttons「Available」和「Leave」來自數據庫。它可以超過2個值(「可用」和「離開」)。我需要在客戶端JavaScript中識別並以編程方式設置它的值。我需要使用類似的代碼,因爲它是一個UserControl'$ find('<%= FindControl(「txtUser」)。ClientID%>')' –

+0

使用JS函數的唯一名稱(http://www.telerik .com/support/kb/aspnet-ajax/details/using-dynamic-unique-names-for-javascript-functions)並在每個實例中注入所需的ID與服務器代碼塊 – rdmptn