Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
Posted
Updated 24-Oct-13 23:28pm
v3

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
 
Share this answer
 
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
 
Share this answer
 
this is my script put this in header
XML
<script type="text/javascript">
    function ChangeValue() {

        document.getElementById("<%=TextBox1.ClientID %>").value = "hello";
        return false;
    }
</script>



put following code in div of body

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return ChangeValue()" AutoPostBack="false" onclick="Button1_Click" />

<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"  ></asp:TextBox>


Happy coding!!!
 
Share this answer
 
v4
Hi,

Actually you have two query, I am not getting you in your textbox query. For FileUpload control in Update panel try to use AsyncFileUpload control[^]. Normal FileUpload control will not work Asynchronously.

Best luck.
-Amit
 
Share this answer
 
Comments
GaneshKale22 25-Oct-13 5:30am    
my FileUpload control is working fine. but, i have problem for reading the textbox value.
AmitGajjar 25-Oct-13 5:34am    
For that please check answer @ http://stackoverflow.com/questions/5838094/how-to-access-control-in-updatepanel-through-javascript.
JoCodes 25-Oct-13 5:55am    
So now the problem is not able to retrieve the changed value of the textbox since its in disabled mode?
AmitGajjar 25-Oct-13 5:59am    
No it should work with $('#txtID').val()
JoCodes 25-Oct-13 6:06am    
$('#txtID').val() , is not fetching the changed value?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900