2014年10月13日 星期一

[Web Form] 下拉選單jQuery塞值,後台取不到值

因為舊站台翻新

原本下拉選單要postback回後台取值方式

都改成jQuery的方式,在前台轉換


在前台submit到後台取值存檔時

<asp:Button runat="server" Text="確定送出" OnClick="submit" /> 

下拉選單

<select name="selectid" id="selectid" runat="server"></select>

在後台

string select_id = selectid.Value;

竟然是取不到值的,其實這邊我也不知道為什麼!

如果有哪位高手大大,知道的話,麻煩留言告知小弟一下,感謝!


最後解決的方式是

先建一個hidden,在下拉選單轉換時

<input type="hidden" name="hidselectid" id="hidselectid" runat="server" />
var selectid = $('#ctl00_ContentPlaceHolder1_selectid');
selectid.change(function () {
    $('#ctl00_ContentPlaceHolder1_hidselectid').val(selectid.val());
});

把值塞到hidden裡,這樣後台就可以取到hidden裡的值來用了。

沒有留言:

張貼留言