在ASP.NET更新的隐藏字段通过JavaScript [英] Updating a Hidden Field in ASP.NET via JavaScript

查看:124
本文介绍了在ASP.NET更新的隐藏字段通过JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一些JavaScript,我被告知要融入我们的ASP.NET站点。我想这将是简单,但它的转向了是一个小小的挑战。

I inherited some JavaScript that I was told to integrate into our ASP.NET site. I thought this would be straightforward but it's turning out to be a bit of a challenge.

在code看起来是这样的:

The code looks something like this:

<SELECT id="Question1" name="Question" onchange="updateQuestion();">                 
<OPTION value="notChosen">--Please Select One--</OPTION>
<OPTION value="in">India</OPTION>
<OPTION value="de">Germany</OPTION>                     
<OPTION value="fr">France</OPTION>                
<OPTION value="us">United States</OPTION>                     
<OPTION value="ch">Switzerland</OPTION>                
</SELECT> 

我们的目标是从这个HTML控件到ASP.NET的价值,然而这控件本身被动态地由JavaScript的另一块产生的,所以我不能只是改变这一个asp.net控制。我的解决办法是添加的onchange =updateQuestion();方法,这个JS会拿这些SELECT标签和值放入一个ASP.NET控件:

The goal is to get the value from this HTML control into ASP.NET, however this control itself is being dynamically generated by another chunk of javascript, so I can't just change this to an asp.net control. My solution was to add the onchange="updateQuestion();" method, this JS will take these SELECT tags and place the values into an ASP.NET control:

function updateSecQ() {
    var sQuestion = document.getElementById('<%=sQuestion.ClientID%>');
    sQuestion.Value = "";
    var questions = document.getElementsByName('Question');
    for (question in questions) {
        if (questions[question].value != null)
            sQuestion.Value += questions[question].value + ",";
    }
    alert(sQuestion.Value);
}

如你所见,这就是希望更新ASP.NET控件:
    &LT; ASP:HiddenField ID =sQuestion=服务器值=/&GT;

这似乎所有的工作,但是当我转到形式在服务器端提交我看到sQuestion.Value仍然=

This appears to all work, however when I goto the server side on the form submit I see that sQuestion.Value is still = "".

我不太知道我做错了这里,任何投入将是非常美联社preciated。感谢您的时间。

I'm not quite sure what I've done wrong here, any input would be much appreciated. Thank you for your time.

推荐答案

说不上约ASP.net,但我知道在浏览器的DOM,一个隐藏字段的值是值全部小写,没有价值。它的属性值,浏览器将提交,并通过设置sQuestion.Value,你无法设置其提交的值。

Dunno about ASP.net, but I know in the browser DOM, a hidden field's value is value all lower case, not Value. It's the value attribute that the browser will submit, and by setting sQuestion.Value, you've failed to set its submitted value.

这篇关于在ASP.NET更新的隐藏字段通过JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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