本文介绍了如何从codebehind函数调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

public void LoadMessages()
{
   DataTable dt = m_Data.GetMessages(m_UserID_Login);
   if (dt.Rows.Count > 0)
   {
      foreach (DataRow row in dt.Rows)
      {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "sendPrivateMessagetest();", true);
      }
   }
}





无效,请帮助



not working , Please Help

推荐答案

public partial class Default : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		LoadMessages();
	}

	public void LoadMessages()
	{
		DataTable dt = m_Data.GetMessages(m_UserID_Login);
		if (dt.Rows.Count > 0)
		{
		  foreach (DataRow row in dt.Rows)
		  {
			Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "sendPrivateMessagetest();", true);
		  }
		}
	}
}



ASPX代码:


ASPX code:

<head runat="server">
    <title></title>
    <script type="text/javascript">
        function sendPrivateMessagetest() {
            alert('message');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>



注意:确保在页面中注入了JavaScript函数。


Note: Make sure that the JavaScript function is injected in your page.


这篇关于如何从codebehind函数调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:41