如果按下了specvic服务器控件,则在回发时执行javascript

execute javascript on postback if specfic server control is pressed

本文关键字:javascript 执行 specvic 服务器控件 如果      更新时间:2023-09-26

我真的不懂javascript。我使用以下代码在按钮上创建一个弹出窗口,点击一些在线ASP.NET服务器控件/HTML:

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911/extended/ExtendedControls.debug.js"
    type="text/javascript"></script>
<script type="text/javascript">
    Sys.debug = true;
    var popup;
    Sys.require(Sys.components.popup, function () {
        popup = Sys.create.popup("#popup", {
            parentElementID: "target",
            onShow: '{AnimationName: "Sequence", AnimationChildren: [{AnimationName:"HideAction", visible: true},{AnimationName:"FadeIn"}]}'
        });
    });  

这个按钮打开内容,效果很好:

<input type="button" onclick="popup.show()" value="Search Stories" />

我的问题是,其中两个服务器控件使框在回发时消失。回发对他们中的一个来说肯定是必要的。这对我来说很有意义,因为页面正在刷新,而且按钮还没有按下。在特定情况下(导致回发的这两个操作之一),如何使页面回发并显示弹出窗口?

你可以试试这个:

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(this.GetType(), "ShowPopup"))
{
  String cstext1 = "alert('Hello World');";
  cs.RegisterStartupScript(this.GetType(), "ShowPopup", "popup.Show()", true);
}