Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从服务器端asp.net调用Javascript函数_Javascript_C#_Asp.net - Fatal编程技术网

如何从服务器端asp.net调用Javascript函数

如何从服务器端asp.net调用Javascript函数,javascript,c#,asp.net,Javascript,C#,Asp.net,我在GridView中有一个Textbox,我想更改标签。如果Textbox中的文本已更改,则为Text。但我无法调用在.cs页面中编写的javascript函数。TbUnitCost\u texchanged方法中是否有错误 这是我的aspx页面 <ItemTemplate> <asp:TextBox Style="text-align: right" ID="TbUnitCost" runat="server" Width="80px" Text='<%#Bind

我在
GridView
中有一个
Textbox
,我想更改标签。如果Textbox中的文本已更改,则为Text。但我无法调用在.cs页面中编写的javascript函数。
TbUnitCost\u texchanged
方法中是否有错误

这是我的aspx页面

<ItemTemplate>
  <asp:TextBox Style="text-align: right" ID="TbUnitCost" runat="server" Width="80px" Text='<%#Bind("Unit_Cost")%>' AutoPostBack="true" OnTextChanged="TbUnitCost_TextChanged"  TextMode="Number"></asp:TextBox>
 </ItemTemplate>
javascript函数是:

<script type ="text/javascript">
    function calculateTotalCost(rowNo, GridName) {                        

        if (GridName== 'GridWorkExpenses') {
            var rowscount = document.getElementById('<%=GridWorkExpensesSheet.ClientID%>').rows.length;
            return calculateTotalUnitCost("GridWorkExpensesSheet", rowscount,rowNo);
        }
   }
 </script>     

函数calculateTotalCost(rowNo,GridName){
如果(GridName=='GridWorkExpenses'){
var rowscont=document.getElementById(“”).rows.length;
返回calculateTotalUnitCost(“网格费用表”,第行,第行);
}
}
尝试使用以下方法:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "CalculateTotalCost", true);
描述任何进一步的问题(如果有)

尝试使用以下方法:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "CalculateTotalCost", true);
描述任何进一步的问题(如果有)

ScriptManager.RegisterStartupScript(this,this.GetType(),“Script”,“CalculateTotalCost”,false);
这是另一种方法

这是一个非常古老的讨论[1]:

也请参考此项。

ScriptManager.RegisterStartupScript(this,this.GetType(),“Script”,“CalculateTotalCost”,false);
这是另一种方法

这是一个非常古老的讨论[1]:


也请参考此项。

您好,您必须将所有命令写入一个字符串中

 ScriptManager.RegisterClientScriptBlock((sender as Control), GetType(), "jQueryCommand", "$('.MenuLoginLink').hide();$('.MenuUsername').show();$('.MenuUsername').text('" + Currentmember.Mobile  + "');$('.MenuExit').show();" +
                " $('.btnLoginInFriends').hide();$('#HiddenSession').val('" + int.Parse(Session["CurrentUserID"].ToString()) + "');", true);

您好,您必须在一个字符串中写入所有命令

 ScriptManager.RegisterClientScriptBlock((sender as Control), GetType(), "jQueryCommand", "$('.MenuLoginLink').hide();$('.MenuUsername').show();$('.MenuUsername').text('" + Currentmember.Mobile  + "');$('.MenuExit').show();" +
                " $('.btnLoginInFriends').hide();$('#HiddenSession').val('" + int.Parse(Session["CurrentUserID"].ToString()) + "');", true);

不清楚。。你到底想要实现什么?您想从客户端还是服务器端更改它?您已经设置了AutoPostBack=“true”,这意味着页面将被提交到服务器,我想在类似OnItemDataBound的事件中,您可以附加javascript调用,使AutoPostBack=“false”我不能使用Textbox.Attributes.Add()方法调用javascript函数吗?为什么要从服务器端调用它?您可以在Js onchange事件上执行此操作。不清楚。。你到底想要实现什么?您想从客户端还是服务器端更改它?您已经设置了AutoPostBack=“true”,这意味着页面将被提交到服务器,我想在类似OnItemDataBound的事件中,您可以附加javascript调用,使AutoPostBack=“false”我不能使用Textbox.Attributes.Add()方法调用javascript函数吗?为什么要从服务器端调用它?您可以在JSOnChange事件上执行此操作。