0
我需要从代码隐藏ASP.NET(C#)到Javascript函数的同步调用。ASP.NET - >同步调用JavaScript函数
我试过ScriptManager.Registerclient,但是因为这是异步的,所以这是不好的。在返回值(更新UpdatePanel)以检查操作是否有效之前,我需要在JavaScript中进行一些测试。
对于短码例如:
myButton_click(object sender, EventArgs args)
{
<callJavascriptSynchronous>
if (MyHiddenField.Value == "true")
//Do
else
//Don't
}
MyHiddenField是一个UpdatePanel内。对于javascript函数:
function javascriptFoo(myInteger)
{
var returnValue = window.external.TestInteger(myInteger);
document.getElementById('<%=MyHiddenField.ClientID%>').value = returnValue;
}
UpdatePanel的是这样的:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:HiddenField ID="MyHiddenField" runat="server" ClientIDMode="Static" Value="" Visible="false"/>
</ContentTemplate>
在同步调用有什么建议?
谢谢!
编辑:新增全码:
MyPage.aspx:
function javascriptFoo(myInteger)
{
var returnValue = window.external.TestInteger(myInteger);
document.getElementById('<%=MyHiddenField.ClientID%>').value = returnValue;
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:HiddenField ID="MyHiddenField" runat="server" ClientIDMode="Static" Value="" Visible="false"/>
</ContentTemplate>
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">
MyPage.aspx.cs:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
ScriptManager.RegisterStartupScript(UpdatePanelContext, UpdatePanelContext.GetType(), "AlertTest", "AlertTest()", true);
string sVal = HiddenFieldContext.Value;
if (sVal == "true") //do
else //don't
}
回传会对我没有好处,因为这是在操作中发生的。我实际上是在GridView.RowCommand事件中执行此操作。 – user1782815 2014-09-04 08:00:35
'myButton_click'在哪里? – Alexander 2014-09-04 08:01:59
它在哪里? 我需要测试Gridview_rowCommand事件中的数据。 我能够做到这一点,它的工作原理,但呼叫不同步。 –
user1782815
2014-09-04 08:03:36