弹出窗口不在服务器端工作,但在本地工作

时间:2014-04-30 06:04:43

标签: javascript jquery asp.net popup

我正在使用jQuery弹出窗口,用户将从中保存数据。当我从本地计算机(Web项目)运行应用程序时,弹出窗口显示并且一切正常,但是一旦我尝试在服务器端执行相同的功能,它就不会在表单上显示弹出窗口。

我使用以下jscript:

<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/jquery-ui-1.8.17.custom.min.js"></script>

我显示模态弹出窗口的脚本如下:

<script type="text/javascript">
function showdialogServiceType() {
    $(function () {
        $("#dialogServiceType").dialog("open");
    });
    return false;
}

$(function () {
    $("#dialogServiceType").dialog("destroy");
    var dlgServiceType = $("#dialogServiceType").dialog({
        title: "Service Type",
        autoOpen: false,
        modal: true,
        resizable: true,
        width: 'auto',
        buttons: {
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });
    dlgServiceType.parent().appendTo(jQuery("form:first"));
});
</script>

为了显示上述查询,我​​在网格视图中使用了图像按钮。我按如下方式调用此弹出窗口:

protected void SelectVehicleReg_Click(object sender, EventArgs e)
{
    ImageButton lb = sender as ImageButton;
    GridViewRow row = (GridViewRow)lb.NamingContainer;
    txtRowID.Text = row.Cells[0].Text;
    txtVehicleReg.Text = row.Cells[1].Text;

    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "popServiceType", "showdialogServiceType();", true);
}

我还尝试过一个带有jquery的简单消息框,但这不起作用(虽然它适用于服务器端的其他项目)。弹出窗口在发布后不想在这个Web项目中工作。

我的测试消息对话框:

$(function () {
    $("#dialog").dialog("destroy");
    $("#dialog").dialog({
        title: "Message",
        autoOpen: false,
        modal: true,
        buttons: {
            Ok: function () {
                $(this).dialog("close");
            }
        }
    });
});
function showMessage() {
    $(function () {
        $("#dialog").dialog("open");
    });

    return false;
} 

<div id="dialog" style="display: none">     
    <asp:Label ID="lbljQMessage" runat="server" Text=""></asp:Label>
</div>

protected void Button1_Click(object sender, EventArgs e)
{
    lbljQMessage.Text = "Test";
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "popUpMessage", "showMessage();", true);
}

我做错了吗?

1 个答案:

答案 0 :(得分:1)

您确定正确引用了jquery吗?我的意思是服务器将具有与本地计算机不同的路径。在浏览器中使用内置调试器(F12)来查看是否正确包含了js文件(如果是这样,它们将显示为链接,您可以打开它)。如果脚本在同一个调试器中执行,您也可以检查。如果您使用了chrome,请转到“源”选项卡并选择您的站点。您可以在脚本中放置断点。然后你会看到脚本是否被执行或者是否有错误。