发布改变了ASP.NET禁用的控件的值 [英] Posting changed values of a disabled control in ASP.NET

查看:133
本文介绍了发布改变了ASP.NET禁用的控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例

 < ASP:文本框ID =txbx=服务器文本=1启用=FALSE/>


  1. 与值'1'的文本框设置为禁用。


  2. 该texbox值更新为'2'使用javascript。


  3. 在发布到服务器的初值 1 被使用。


我曾尝试覆盖具有以下VB code此功能:

  Page.Form.SubmitDisabledControls = TRUE

为什么不更新值后的服务器?

注意

更新值后正确'2'如果启用=真正的

 < ASP:文本框ID =txbx=服务器文本=1启用=真/>


解决方案

实际上发生的事情是,如果你设置已启用=假对于一些ASP控制,即特定的控制将呈现在客户端,但它的类将被设置为aspNetDisabled其中prevents它的值进行编辑。我发现没有办法编辑/改变这一类。所以,你可以使用任何客户端脚本如JavaScript不能编辑它的值。

当您尝试发布它的值回服务器时,使用初始值这是存在于服务器上。

如果您启用了控制,它就会为你想呈现在那种情况下,你可以访问/修改它的值。

EXAMPLE

<asp:TextBox ID="txbx" runat="Server" Text="1" Enabled="false" />

  1. A textbox with value '1' is set to disabled.

  2. The texbox value is updated to '2' using javascript.

  3. When posted to the server the intial value '1' is used.

I have tried overwriting this functionality with the following VB Code:

Page.Form.SubmitDisabledControls = True

QUESTION

Why doesn't the updated value post to the server?

NOTES

The updated value post correctly '2' if enabled="true"

<asp:TextBox ID="txbx" runat="Server" Text="1" Enabled="true" />

解决方案

Actually what happens is if you set Enabled = false for some ASP control, that particular control will rendered on client-side but its class will be set as "aspNetDisabled" which prevents its value to be edited. I found no way to edit/change this class. So, you can't edit its value using any client-side script like JavaScript.

When you try to post its value back to server, the initial value is used which was there in server.

If you enable the control, it gets rendered and in that case you can access/edit its value as you want.

这篇关于发布改变了ASP.NET禁用的控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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