[英]I want hidden field value from c# to my javascript
i have hidden field run at server and i set value to it in my c# code and when i click a button i want that value transfer to my javascript or jquery , and also that button is in the update panel. 我在服务器上运行了隐藏字段,并在c#代码中为其设置了值,当我单击一个按钮时,我希望该值传输到我的javascript或jquery,并且该按钮在更新面板中。 so no postback occurs.
因此不会发生回发。 i called it by registerstartupscript but didnt work , here is my c# code
我通过registerstartupscript调用了它,但是没有用,这是我的C#代码
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
base64String = "data:image/png;base64," + Convert.ToBase64String(imageBytes);
}
hidImgQR.Value = base64String;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "myScript", getImgQR();", true);
in jQUERY 在jQUERY
function getImgQR()
{
alert($("input[id$=hidImgQR]").val());
}
i have tried many different way but it doesnt work, may be because of update panel it doesnt take latest value but only the defalut value i have assigned .. 我尝试了许多不同的方法,但是它不起作用,可能是因为更新面板没有最新的值,但是只有我分配的默认值..
你也可以做这样的事情
$('#' + '<%= hidImgQR.ClientID %>').val();
You can do : 你可以做 :
alert($("<%= hidImgQR.ClientID %>").val());
call button's click inside pageLoad()
: 呼叫按钮在
pageLoad()
内部的点击:
<script type="text/javascript">
function pageLoad() {
$("#yourbtn").click(function(){
alert($("<%= hidImgQR.ClientID %>").val());
});
}
</script>
Have Hidden field control 有隐藏的现场控制
<asp:HiddenField id="fileId" runat="server" value='Nishant' />
JavaScript Code which will return hidden field Value JavaScript代码将返回隐藏字段值
document.getElementById("<%= fileId.ClientID %>").value;
Note You can also make ClientIDMode="Static"
use this property for your control and retrieve it by id itself 'fileId' ForInstance: 注意您还可以使
ClientIDMode="Static"
使用此属性作为控件,并通过ID本身'fileId'ForInstance检索它:
<asp:HiddenField id="fileId" runat="server" ClientIDMode="Static" value='Nishant' />
and use JavaScript code: 并使用JavaScript代码:
document.getElementById("fileId").value;
It will also return Nishant but Id will be static. 它还将返回Nishant,但Id将是静态的。 Use only
ClientIDMode="Static
when you are sure that no one control has same Id. 当您确定没有任何一个控件具有相同的ID时,请仅使用
ClientIDMode="Static
。
Runnable Asp.Net Code http://runnable.com/UjsLAmP-yM0VAADp/asp-net-how-to-get-server-control-value-in-javascript 可运行的Asp.Net代码http://runnable.com/UjsLAmP-yM0VAADp/asp-net-how-to-get-server-control-value-in-javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.