从服务器端在这里我想ASP.NET AJAX调用客户端功能
我有客户端按钮事件。点击呼叫sgnPdf(ID)后,如果我可以签署PDF。
I have Client-Side button event. After click call sgnPdf(ID) if I can sign PDF.
[MyForm.aspx]
[MyForm.aspx]
<script type="text/javascript">
<% if (ViewData.CanSignPdf){ %>
$(function() {
$("#<%=btnSend.ClientID %>").click(function() {
if ($('.IgnoreCheckBox').is(':checked')) {
sgnPdf(<%=ViewData.NoticeID %>);
return false;
};
});
});
<% } %>
</script>
但我需要后,按一下按钮调用从服务器端此功能。
But I need call this function from Server side after button click.
[MyForm.aspx.cs]
[MyForm.aspx.cs]
protected void BtnSendClick(object sender, EventArgs e)
{
FormUnbindData();
SaveMYData();
//Here i want call client function sgnPdf(ID). How can I do this?
ShowMyMessage();
}
OK,你需要做的只是简单。例如呼叫提醒(信息)在那里。
OK, you need to do just simply. For example call alert("message") in there.
好了,它的作品!但我需要调用客户端从服务器端(C#)方法(JavaScript)的同步,becouse客户端的方法没有启动,直到服务器端方法结束(例如button_click事件)。
Ok, its works!!! but i need call client-side method(javascript) from server-side(C#) synchronously, becouse client-side method not starting until server-side method ends (for example button_click event).
我试试这个:
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "anyId", "<script type='text/javascript'>alert('This is my alert message');</script>", true);
和不采取行动,什么都没有。
and no action, nothing.
使用此按钮时,点击:
ClientScript.RegisterClientScriptBlock(Page, typeof(Page),sgnPdf(ID), true);
OR
<asp:Button OnClientClick = "sgnPdf(ID)"/>
使用这种在页面加载:
RegisterStartupScript("Unique key", "sgnPdf(ID);");
下面是一个参考