从jQuery的ASP.NET的残疾人输入设定值 [英] Set value of disabled input from jQuery for ASP.NET

查看:83
本文介绍了从jQuery的ASP.NET的残疾人输入设定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图找出如何设置的JavaScript里面的输入的值与的确保它发布到ASP.NET服务器。它必须的停用的领域了。

Trying to figure out how to set input's value inside JavaScript and make sure it is posted to the server in ASP.NET. It has to be disabled field too.

我试过这样:

<asp:TextBox ID="DriverIdTextBox" runat="server" enabled="false" />

然后在jQuery的:

And then in jQuery:

$("*[id$='DriverIdTextBox']").val("JAVA");

这贴的时候不给我JAVA的后端。
当启用文本框 - 我得到的服务器就好了此值。我试图使能控制和禁用客户方像这样:

This when posted doesn't give me "JAVA" on backend. When I enable textbox - I get this value on server just fine. I tried to enable control and disable on clientside like so:

$("*[id$='DriverIdTextBox']").val("JAVA").prop("disabled", true);

同样的问题 - 值不会发布到服务器

Same problem - value is not posted to server.

基本上我想设置为只读标签/输入任何使用户可以读取它,但在同一时间,我想,当用户提交表单将其发布到服务器上。我怎样才能做到这一点?

Basically I want to set read-only label/input whatever so user can read it but at the same time I want to post it to server when user submits form. How can I achieve this?

推荐答案

它不会,如果你有禁用的文本框回发到服务器。

It will not post back to the server if you've got the textbox disabled.

设置标签,文本框的值,并设置一个隐藏字段的值也是如此。

Set a label to the value of the textbox and set a hidden field to the value as well.

 <asp:HiddenField ID="hdnDriverId" runat="server" />
 <asp:Label ID="lblhdnDriverId" runat="server" Text="Label"></asp:Label>

    this.lblhdnDriverId.Text = "";
    this.hdnDriverId.Value = "";

$("*[id$='lblhdnDriverId']").val("JAVA");
$("*[id$='hdnDriverId']").val("JAVA");

这篇关于从jQuery的ASP.NET的残疾人输入设定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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