更改使用JavaScript的输入值 [英] Changing input value using javascript

查看:122
本文介绍了更改使用JavaScript的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个原因,这并不工作,但我不能找到一个。在我的asp.net应用程序我创建了一堆在C#中隐藏的输入,然后尝试修改它们在JavaScript之前,我叫他们回服务器。

我的C#code:

  hidden3 =新HtmlInputHidden();
    hidden3.ID =总;
    hidden3.Value = index.ToString();
    this.Controls.Add(hidden3);

我的javascript code:

  MOD =的document.getElementById(总);
     mod.value =的newval;

我可以打电话值回罚款,但它不会改变。我还增加了警报的原始值,然后将该值变化值后,他们都表现出了罚款。然而,code是从来没有改变过,所以当我拉值

要获取值回我使用这一点;

  HtmlInputHidden hiddenControl =(HtmlInputHidden)的FindControl(总);


解决方案

动态创建这些控件,它们在每个回发到创建。然而,这些都应该pferably的Page_Load $ P $在Page_Init事件处理程序之前建成。如果这些都在Pag​​e_Load中创建视图状态已被处理和控制,不能从张贴值设置

I've been looking for a reason why this doesn't work, but I can't find one. In my asp.net application I create a a bunch of hidden inputs in c# and then try to modify them in javascript before I call them back to the server.

My c# code:

    hidden3 = new HtmlInputHidden();
    hidden3.ID = "total";
    hidden3.Value = index.ToString();
    this.Controls.Add(hidden3);

my javascript code:

     mod = document.getElementById("total");
     mod.value = newVal;

I can call the value back fine but it doesn't change. I have also added alerts for the original value and then the value after changing values and they both show up fine. However the code is never changed so when I pull the values

To get the value back I am using this;

    HtmlInputHidden hiddenControl = (HtmlInputHidden)FindControl("total");

解决方案

These controls are dynamically created and they have to be created in each postback. However, these should be built before Page_Load preferably in Page_Init event handler. If these are created in Page_Load, the view state has already been processed and the control can't be set from the posted value.

这篇关于更改使用JavaScript的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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