Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello, I would like to change the value using javascript in a asp:button to catch the value on the code behind when i click on it, the default value Text="show"

i see the change on the page when i use the javascript "left: ......."
but when i catch the button in code behind with string a = button.text i get the default value "show" and not the value shown on the button on the webpage.

this is the javascript code that changes the text on the button

document.getElementById("hidden1").text = ("Left: " + $(this).parent().dialog('widget').position().left + " Top: " + $(this).parent().dialog('widget').position().top);

// click the button
document.getElementById("hidden1").click();


Also i don't want to reload the page when the button i clicked, i only want to catch the value in the button from code behind, can ajax solve this?

Can anyone help, Thanks
Posted
Updated 23-Feb-11 23:23pm
v2

1 solution

Its not possible to get the Text value in code behind which you have changed by using javascript. For a detailed reason visit the following link

http://msdn.microsoft.com/en-us/library/system.web.ui.ipostbackdatahandler.aspx[^]

as the default button Server control dowsn't implement IpostbackDataHandler you will not be able to get the Text data from server side code. So for an alternative approach try to use the HiddenField and update the value when you are updating the text value of the buton control and get the value at the server side.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.aspx[^]
 
Share this answer
 

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