将值从Javascript传递给aspx [英] Passing values from Javascript to aspx
本文介绍了将值从Javascript传递给aspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序需要将Javascript中的变量值传递给ASPX.有人可以告诉我该怎么做吗?
My program needs to pass a variable value from Javascript to ASPX. Can somebody tell me how to do this?
function controlvalue(){
var myTextField = document.getElementById('FileUpload1');
alert("You entered: " + myTextField.value)
}
这里myTextField.value需要传递给aspx
here myTextField.value needs to be pass to aspx
推荐答案
<script type="text/javascript">
function test()
{
var str="value";
document.getElementById("hidden1").value=str;
}
</script>
<input id="hidden1" type="hidden" runat="server" />
<asp:Button ID="Button1" runat="server" OnClientClick="test()"
Text="Button"
onclick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Hidden1.Value);
}
1.我认为您可以轻松地同时使用这两个函数,我的意思是,如果我在客户端使用javascript在txtbox1上写一些文本,则可以从服务器端使用.text检索该文本(前提是该控件禁用了viewstate
).
谁能批准我的理解.我也可能是错的.
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 theviewstate
is disabled for that control).
Could anyone ratify my understanding. i might be wrong too.
U可以使用jquery-ajax来调用页面方法..
示例 [
U can use jquery-ajax to call a page method..
Sample[^]
这篇关于将值从Javascript传递给aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文