2012-04-24 115 views
0

如何在模式框上分配文本框值後獲取代碼隱藏文本框的值?將文本框值分配到同一頁上的模式框

這是模態盒如何出現在頁面上:

<div id="dialog-form" title="Modal Box"> 
    <asp:TextBox ID="Textbox1" runat="server" ReadOnly="True"> 
    <asp:Button ID="Save_Button" runat="server" Text="Save"></asp:Button>   
</div> 

爲了分配上Textbox1的價值,我附上一個JavaScript函數來LinkBut​​ton的上一個GridView(這裏沒有顯示的代碼)通過代碼隱藏基於LinkBut​​ton的點擊:

Dim myLinkButton As LinkButton  
For i As Integer = 0 To GV1.Rows.Count - 1 
    myLinkButton = DirectCast(GV1.Rows(i).Cells(1).FindControl("LinkButton"), LinkButton) 
    myLinkButton.Attributes.Add("onclick", "shopModalPopup('" + .Rows(i).Cells(0).Text & "'); return false;") 
Next 

Rows(i).Cells(0)是在GridView的第一列,它是「ID」。這個ID將被分配到Textbox1而Linkbutton點擊。

的JavaScript代碼是相同的頁面GridView的代碼上:

<script> 
var grid_modal_options = { 
        height: 450, 
        width: 550, 
        modal: true 
       }; 

function shopModalPopup(id) { 
        var DataField = id; 
        grid_modal_options.open = function() { 
         $('#dialog-form #Textbox1').val(DataField); 
        }; 

        $("#dialog-form").dialog(grid_modal_options); 
        $("#dialog-form").parent().appendTo('form:first'); 
       } 
</script> 

當我點擊模態盒保存按鈕,在Textbox1值不能對代碼後來居上。它總是返回空值。怎麼做?非常感謝你。

+0

爲什麼你使用是使用asp文本框的方式 – 2012-04-24 02:41:31

+0

@COLDTOLD:對不起,我已經編輯了上面的代碼。我正在使用asp:textbox,但仍然無法獲得值。 – 2012-04-24 02:45:31

回答

1

請仔細閱讀本

http://www.codeproject.com/Articles/37090/JQuery-UI-Dialog-with-ASP-NET-empty-post-values

我認爲它可以幫助你的問題可能是對話的DIV移到表格外,你可以通過使用參考以上或只是定義另一個隱藏的輸入解決問題和具有相同值的

$('#dialog-form #Textbox1').val(DataField); 
$('hiddenfield').val(DataField); 

更新隱藏輸入,然後從隱藏字段讀出的值

不知道它是最好的答案,但可能作爲一個快速修復

+0

非常感謝您的想法。有用! :) – 2012-04-24 11:03:56

0

它沒有工作沒有Readonly="true"?如果是,請在您的<asp:textbox>中將Readonly="true"替換爲Enabled="false"

我沒有測試過這個,但我記得Readonly導致我過去這樣的問題。

+0

嗨,謝謝,但它不起作用。 :) – 2012-04-24 11:03:13

相關問題