[英]call c# function from javascript onclick event button
how to use something like this : 如何使用这样的东西:
<script>
google.maps.event.addListener(marker, "click", function (e) {
var infoWindow = new google.maps.InfoWindow({
content:
'<div><input type="text" id="txt_newpl" value="place name"/>' +
'</br> <input type="button" id="btn_newpl" value="submit" onclick="btn_newpl_Click" /></div>'
});</script>
and c# code is like this 和c#代码是这样的
protected void btn_newpl_Click(object sender, EventArgs e)
{...}
how can call this c# function from javascript event click 如何从javascript事件点击调用此c#函数
To trigger button event, you have to add this line of code in javascript. 要触发按钮事件,您必须在javascript中添加此行代码。
document.getElementById("btn_newpl").click();
Your button must have runat="server"
and OnServerClick="btn_newpl_Click"
attributes. 您的按钮必须具有
runat="server"
和OnServerClick="btn_newpl_Click"
属性。
If your problem is that the input
element is in javascript string , than you can extract the string value of input
and concatenate to your string on client side . 如果您的问题是
input
元素是javascript字符串 ,那么您可以提取 input
的字符串值并连接到客户端的字符串。
<input type="button" id="btn_newpl" value="submit"
OnServerClick="btn_newpl_Click"
runat="server" />
<script>
var tmp = document.createElement("div");
tmp.appendChild(document.getElementById('btn_newpl'));
google.maps.event.addListener(marker, "click", function (e) {
var infoWindow = new google.maps.InfoWindow({
content:
'<div><input type="text" id="txt_newpl" value="place name"/>' +
'</br>'+tmp.innerHTML+'</div>'
})
});
</script>
Please note that you don't actually call a C# function , you just trigger the click event on webforms and a postback to sever will be done. 请注意,您实际上并没有 调用C#函数 ,只需触发webforms上的click事件,就会完成对服务器的回发 。 The server will figure out which event has been triggered and will execute the C# function.
服务器将确定哪个事件已被触发并将执行C#功能。
Source: How to call a code behinds button click event using javascript 来源: 如何使用javascript调用代码隐藏按钮单击事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.