在asp.net中使用Java脚本 [英] use Java script in asp.net

查看:99
本文介绍了在asp.net中使用Java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,并且我想通过使用Java脚本更改选择或下拉控件的值来更改其text属性.我做的没有错误.

但是问题是当我更改text属性时,之后如果我通过任何控件(例如任何其他下拉控件的selectindexchanged事件,例如任何往返)执行任何往返操作,则lable的text属性将刷新或更改为其原始文本

I have a label, and i want to change it''s text property by changing the value of select or dropdown control by using java script. i have done without error.

But problem is when i change the text property, after that if i do any roundtrip by any control like selectindexchanged event of any other dropdown control such as any roundtrip then that text property of lable is flushing or changed to it''s originnal text

推荐答案

这是因为标签不是持久性的.因此,当您使用javascript对其进行更改时,它将恢复其旧值.您应该在selectindexchanged事件中更改标签文本服务器端.这样,标签更改将保持不变并保持该值.

另一种肮脏的方法是在页面加载完成时也使用javascript更新标签值.但是,我建议不要使用此方法,而应采用服务器端方法.

祝你好运!
This is because a label is not persistent. So when you change it with javascript it will have it''s old value back. You should change the label text server side in the selectindexchanged event. That way the label change will be persistent and will keep that value.

Another dirty way would be to also update the label value using javascript when loading of the page is completed. I would however advice not to use this method and go with the server side approach.

Good luck!


或使用Update Panel如果可以避免往返,那么它将正常运行.
Or use Update Panel if you can avoid round trip, then will function correctly.


这篇关于在asp.net中使用Java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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