如何从updatepanel值读取textbox vlaue来自javascript和textbox被禁用 [英] How to Read textbox vlaue from updatepanel value comes from javascript and textbox is disabled

查看:96
本文介绍了如何从updatepanel值读取textbox vlaue来自javascript和textbox被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.aspx页面的updatepanel中有一个文本框。我必须使用javascript更改texbox的值。但是我无法将textbox的值更改为我的字符串变量。如果我删除更新面板然后它将正常工作,但我需要updatepanel并更改textbox的值,这是javascript。我也在更新面板中使用fileupload控件为此目的我已将我的保存按钮作为PostBackTrigger放在触发器中。如果启用了文本框但是我希望文本框被禁用/只读,则读取texxtbox的值。在禁用/只读条件我想读取来自javascript的文本框值。我的FileUpload控件工作正常。但我无法准备文本框更改值

所以,请帮帮我...

解决方案





你能在这里发布你的代码吗?

以下用于更新文本框的javascript代码适用于我:



document.getElementById('txt1')。value =新值;



我可以在后面的代码中访问更改后的值。我的页面中有更新面板控件。



希望这会有所帮助。

-SP


如果您使用更新面板,则必须使用javascript更改文本框值,您可以使用以下代码更改值,然后再检查以下说明。



1.如果您没有返回任何文本框中指定值的值将替换为之前的值,则在将新值分配给文本框后,确保您返回false。



2.从这里下载新的jquery库



http://code.jquery.com/jquery-1.10.2.min.js [ ^ ]



使用这样的代码



Sys.WebForms.PageRequestManager.getInstance()。add_initializeRequest(function(){


< blockquote>(<%= Button1.ClientID)。click(function(){

document.getElementById(<%= TextBox1.ClientID%>)。value =hello ;

});

});





< asp:button id =Button1runat =servertext =Clickxmlns:asp =#unknown>



< asp:textbox id =TextBox1runat =serverxmlns:asp =#unknown>





并在内部添加相同的代码document.ready function


I have one textbox in updatepanel in .aspx page. I have to change value of texbox using javascript. But I am not able to get changed value of textbox into my string variable. If I remove update panel then it will work fine but I need updatepanel and change value of textbox thorogh the javascript. also i am using fileupload control inside the update panel for that purpose i have put my save button in Triggers as PostBackTrigger. value of texxtbox is read if textbox is enabled but i want textbox is disabled/readonly. at disabled/readonly condition i want to read textbox value which comes from javascript. also my FileUpload control is working fine. but i am uanble to ready textbox changed value
so, please help me...

解决方案

Hi,

Can you post your code here?
The below javascript code for updating text box works for me:

document.getElementById('txt1').value = "New Value";

And i can access the changed value in my code behind. I have update panel control in my page.

Hope this helps.
-SP


If you have to change your textbox value using javascript if you are using update panel you can use the following code for changing the value and before doing that check the following instructions.

1. Makesure that you are returning false after assigning the new value to the textbox if you are not returning anything your assigned value in the textbox will replace to the previous value.

2.Download the new jquery library from here

http://code.jquery.com/jquery-1.10.2.min.js[^]

Use your code like this

Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(function () {


("<%=Button1.ClientID").click(function(){
document.getElementById("<%=TextBox1.ClientID %>").value = "hello";
});
});


<asp:button id="Button1" runat="server" text="Click" xmlns:asp="#unknown">

<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown">


And add the same code inside the document.ready function


这篇关于如何从updatepanel值读取textbox vlaue来自javascript和textbox被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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