简体   繁体   English

如何使用asp.net viewstate使用javascript

[英]How to user javascript with asp.net viewstate

I have UL in my page, and it is empty. 我的页面中有UL,而且它是空的。 I start populating it with LI using javascript. 我开始用LI使用javascript填充它。

How can I use this newly added dynamic data in the asp.net in the postback phase? 如何在回发阶段在asp.net中使用这个新添加的动态数据?

that is because my submit button is asp.net control. 那是因为我的提交按钮是asp.net控件。 I do not want to use JS POST. 我不想使用JS POST。

thanks 谢谢

LI is not transferred over POST. LI不通过POST转移。 Only elements of form: INPUT (text, hidden...), OPTIONS, are passed. 只传递表单元素:INPUT(text,hidden ...),OPTIONS。 So the simplest way is create hidden field 所以最简单的方法是创建隐藏字段
<input type='hidden' name='myData' id='myData' ...

and at ASP.net side access just created control by 并在ASP.net端访问刚刚创建的控件

HttpRequest request = HttpContext.Current.Request;
String value = request.Form["myData"]

I've done this sort of thing in the past by populating a hidden field with the dynamic data to be posted back, you could either - 我过去做过这种事情,通过填充隐藏的字段来回发动态数据,你可以 -

  • Fire a JavaScript event before postback that parsed the data out of the UL into a hidden field 在回发之前触发JavaScript事件,将数据从UL解析为隐藏字段

or 要么

  • Update the hidden field as you update the contents of the UL 更新UL的内容时更新隐藏字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM