Javascript变量看起来像是被分配但实际上它们不是

时间:2015-05-28 11:34:36

标签: javascript asp.net

我在后面的C#代码中有一些RegisterStartupScript,它将某些字段的某些值分配给面板的某些控件,当它打开时。

面板中的控件显示它们的值已被正确分配,但实际上它们的工作方式就好像从未分配过一样,我已经在我的aspx页面的dinamic视图中检查了这一点。

例如:这是一个启动脚本的指令:document.getElementById(" MainContent_Textbox1215")。value =' CALL CENTER';实际上当我看到它显示在呼叫中心的屏幕上的文本框。

但与此同时,这就是代码中的真实内容以及应用程序对未来操作的解释,取自该特定页面的动态视图。

<input name="ctl00$MainContent$Textbox1215" type="text" id="MainContent_Textbox1215" class="listBox" style="width:50%;" />

对于radiobuttons也会发生类似的情况,所以即使在屏幕上看起来似乎是选择了真实的那个是定义为默认的那个,并且可能与所有类型的控件一起使用。

它真的是一个从未被分配给textBox或者radiobutton的值...这是我在编程中见过的最奇怪的东西,希望你能指导我做什么

1 个答案:

答案 0 :(得分:1)

   Even i have faced such a problem once while working with javascript and dotnet.
   What i can say is that you might not have specified the **Value** attribute of
 the textbox in you html that is the reason it is not showing it in your dynamic 
aspx page but the value has been assigned and you can use it anywhere you want.
 This you can verify even with ha plain html page there also i faced the same
 thing. But if you have specified some value for the Value attribute you will see
 old value in the html source but if you try to access it using javascript it will 
show you the new value. I cant figure out the reason behind this behaviour but 
this is what i have experienced.