Solve the problem that the modified value cannot be obtained in the background after the server-side control value is modified using Js.

Source: Internet
Author: User

Solve the problem that the modified value cannot be obtained in the background after the server-side control value is modified using Js.

The project has a small function to modify the value of a server tag in JS, such as document. getelementbyid ("lblclothindex "). innerhtml = result; (for example, from "1" to "2"), but in the background through this. lblclothindex. text returns the old value "1. Later, we found that the latest value can be obtained by calling the hidden control method,CodeAs follows:

1. add a hidden Control <asp: hiddenfield id = "hiddenfield1" runat = "server"/> 2. when JS is used to assign a value to the server tag, it also assigns a document value to the hidden control. getelementbyid ("hiddenfield1 "). value = result; 3. use this. the hiddenfield1.value code obtains the latest value.

Original article: http://www.cnblogs.com/gossip/archive/2010/03/26/1697203.html

ASP. net cannot obtain a value modified by JS: <select id = "ddname" name = "ddname" runat = "server" Disabled = "disabled" onchange = "show (this) "> <option> select a Category </option> </SELECT> one lable: <asp: label id = "lbname" runat = "server" text = "label"> </ASP: Label>

Function show (a) {var sel = document. getelementbyid ("<% = lbname. clientid %> "); SEL. innerhtml = "<span style = 'font-size: 8pt; color: red; '>" +. value + "</span>"; document. getelementbyid ("hidd "). value = SEL. innerhtml ;}

I want to obtain the selected select value. No matter whether it is through request. Form ["ddname"] or by assigning a value to a hidden domain, the background will not be able to get it. Why? Question added:

Select is the first data to be bound through js xmlhttp. Your select value is assigned on the client, and viewstate is not saved. The server cannot naturally obtain the second. What controls are used to hide the domain? If it is hiddenfield, the client value can be obtained on the server.

Original: http://zhidao.baidu.com/question/292323835.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.