简体   繁体   English

回发后的jQuery消息框

[英]Jquery Message Box After Postback

i want to use this plugin in my asp.net application 我想在我的asp.net应用程序中使用插件

i want to show Alert or etc after postback. 我想在回发后显示Alert或其他内容。 i wrote this code but it does not work. 我写了这段代码,但没有用。

string a = null;
a = "csscody.alert('<h1>Information Alert</h1><em>low     level</em><br/><p>© All rights reserved 2006-2010.  </p><p> jQuery examples site  <a href=\\'http://www.csscody.com/\\'>www.csscody.com</a> </p>');return false;";
 ScriptManager.RegisterStartupScript(Page, GetType(), "script", a, true);

This code works Client Side : 此代码适用于客户端:

<p>
        <strong>1.)</strong> <a href="http://www.csscody.com/#" onclick="csscody.alert(&#39;&lt;h1&gt;Information Alert&lt;/h1&gt;&lt;em&gt;low level&lt;/em&gt;&lt;br/&gt;&lt;p&gt;&copy; All rights reserved 2006-2010. &lt;/p&gt;&lt;p&gt; jQuery examples site  &lt;a href=\&#39;http://www.csscody.com/\&#39;&gt;www.csscody.com&lt;/a&gt; &lt;/p&gt;&#39;);return false;">
            Info Message Popup Alert</a></p>
    <p>

Thanks. 谢谢。

在您的C#代码中尝试一下

ClientScript.RegisterClientScriptBlock(typeof(Page), "yourKey", "$().ready(function () { csscody.alert('Hello')});", true);

I believe that the javascript 'onclick' occurs before the postback. 我认为javascript“ onclick”发生在回发之前。 Therefore, if you were to register the jquery on the first page load, then it will trigger the script when the user clicks on the button, but before the postback. 因此,如果要在第一页加载时注册jquery,则当用户单击按钮时,但在回发之前,它将触发脚本。

You can try to inject the code using 'onload' instead of 'onclick' and inject it after the postback occurs. 您可以尝试使用“ onload”而非“ onclick”注入代码,并在发生回发后注入代码。 That way the dialog will show up after the trip to the server. 这样,对话框将在服务器访问之后显示。

I hope that makes sense. 我希望这是有道理的。

您可以使用scriptmanager.registerclientscript代替启动脚本来解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM