开发者

DropDownList selected value set using jQuery is lost after page postback

开发者 https://www.devze.com 2023-03-13 14:05 出处:网络
DropDownList selected value set using jQuery is lost after page postback. My question is how do I retain the value changed/selected using jQuery after the page postback? Please note that I have disabl

DropDownList selected value set using jQuery is lost after page postback. My question is how do I retain the value changed/selected using jQuery after the page postback? Please note that I have disabled my DropDown开发者_运维百科List on the client before posting back and my forms submitdisabledcontrols property set to true declaratively.


You can use view state . Set viewState = true for our drop down.


You could use an html-select instead of an ASP.NET-DropDownList:

<select ID="DropDownList1" runat="server" />

You could access the selected value in following way:

If Not Request(DropDownList1.ClientID) Is Nothing Then
    Dim selectedValue = CInt(Request(DropDownList1.ClientID))
End If


Have you tried to put dropdownlist inside the

if(!isPostBack) 
{ 

ddl.DataSource = "...";

ddl.DataBind(); 

}


Ensure that your jquery

$(document).ready(function(){

is not setting the value, otherwise it's lost on every postback.

You could also submit the form using jquery by having a client onclick event which then enables the dropdown and submits the form, so that when the postback reloads the controls, the view state of the control should be correct.


try using the the jquery live function

$('selector').live('click', function(){ /your-code-goes here/});

this will persist the event on your page

0

精彩评论

暂无评论...
验证码 换一张
取 消