Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program needs to pass a variable value from Javascript to ASPX. Can somebody tell me how to do this?

C#
function controlvalue(){
    var myTextField = document.getElementById('FileUpload1');

 alert("You entered: " + myTextField.value)
}


here myTextField.value needs to be pass to aspx
Posted
Updated 21-Mar-12 1:30am
v3

XML
<script type="text/javascript">

function test()
{
  var str="value";
  document.getElementById("hidden1").value=str;
}
</script>


XML
<input id="hidden1" type="hidden" runat="server" />
        <asp:Button ID="Button1" runat="server" OnClientClick="test()"
 Text="Button"
onclick="Button1_Click" />

C#
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write(Hidden1.Value);
}
 
Share this answer
 
1. I think you can use these two in unison easily, i mean If i write some text on a txtbox1 using javascript on client side I can retrieve that using .text from server side (provided the viewstate is disabled for that control).

Could anyone ratify my understanding. i might be wrong too.
 
Share this answer
 
U can use jquery-ajax to call a page method..

Sample[^]
 
Share this answer
 
hi ,
there are various way to do this:

1) you can use page method to do this. OR

2) use hiddenfield.

hopes this works for you.
 
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