设置在pagepost后面的javascript中的下拉列表中的值 [英] Value set to the dropdown list in javascript lost after pagepost back

查看:95
本文介绍了设置在pagepost后面的javascript中的下拉列表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在用户控件中有一个下拉列表,AutoPost back设置为false,下拉列表'的onchange事件我cal a javascript函数读取所选文本并将其分配给用户控件中的其他文本框。 EnableViewState''设置为true。



但是当有回发时我没有从下拉列表中获取所选值。我错过了什么?应该怎么做?我是否在下拉列表中保留所选值?



我使用Jquery进行客户端脚本编写

解决方案

亲爱的朋友,



在回发之前或从下拉列表中选择值时;从Session变量或nin ViewState变量的下拉列表中存储所选值。



然后每当有回发;

 window_onload()

被调用。在同一事件中您需要使用值填充下拉列表的页面,并在将相同的值填充到下拉列表中之后,然后在JQUERY的帮助下,您可以从先前存储了值的状态变量中为下拉列表设置所选值在回发之前。



* *我不知道你什么时候填写dropdwonlist;所以我建议你一个可以应用的解决方案,或者你可以继续使用自己的方法,并附加我的解决方案,用你自己的解决方案将所选值保存在状态变量中。



请不要忘记将此标记为您的答案,如果它可以帮助您。



问候



Varun Sareen


检查您是否放置了代码行



如果( !Page.IsPostback)
你的下拉列表绑定在这里。


Hello,

I have a drop-down list in a user control, AutoPost back is set to false, dropdown list''s onchange event I cal a javascript function to read the selected text and assign it to some other text box in the user control. "EnableViewState'' is set to true.

BUT when there is a postback I dont get the selected value from the dropdown list. What I am I missing? What should I do to retain the selected value in the dropdown list?

I am using Jquery for client side scripting

解决方案

Dear Friend,

Before postback or on the selection of value from the dropdownlist; store the selected value from the drop down list in Session variable or nin ViewState variable.

Then Whenever there is post back;

window_onload()

is called. In the same event of the page you need to fill your dropdownlist with the values and after the same values have been populated into the dropdownlist, then with the help of JQUERY you can set the selected value for the dropdownlist from the state variable in which you have earlier stored the value before postback.

**I don''t know when you are filling the dropdwonlist; So i have suggested you a solution which you can apply or you can continue with your own method and appending my solution of keeping the selected value in the state variable with your own solution.

Please don''t forget to mark this as your answer if it helps you out.

Regards

Varun Sareen


Check have you placed a code line

If (!Page.IsPostback)
    "Your Dropdown Binding Here."


这篇关于设置在pagepost后面的javascript中的下拉列表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆