我已经在站点母版页上编写了Javascripts。但是,当我调用Javascirpts时,它不起作用。有人能帮我弄清楚吗?谢谢
以下是站点母版页中的Javascript I代码。
<head id="Head1" runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/Styles/jquery-ui-1.9.2.custom.min.css" />
<script type="text/javascript" src="/Scripts/jquery-1.8.3.js"></script>
<script type="text/javascript" src="/Scripts/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript">
function dialog(text) {
$("#text").text(text);
$("#dialog-message").dialog
({
buttons: {
close: function () { $(this).dialog("close"); }
}
});
};
function dialogWithRedirect(text, url) {
$("#text").text(text);
$("#dialog-message").dialog
({
buttons: {
close: function () { location.href = url; $(this).dialog("close"); }
}
});
};
var confirmed = false;
function confirmDialog(obj, text) {
if (!confirmed) {
$("#text").text(text);
$("#dialog-message").dialog({
buttons: {
"Confirm": function () {
$(this).dialog("close");
confirmed = true;
obj.click();
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
}
return confirmed;
};
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
这就是我调用Javascripts的方式。
protected void ImageButtonOK_Click(object sender, ImageClickEventArgs e)
{
if (tbFirstName.Text != "" && tbLastName.Text != "" && tbNickName.Text != "" && tbUsername.Text != "" && tbPassword.Text != "" && tbConfirmPassword.Text != "")
{
if (validateUsername())
{
Database database = new Database();
string sql = "INSERT INTO users " +
" (user_id " +
" ,first_name " +
" ,last_name " +
" ,nickname " +
" ,image " +
" ,username " +
" ,password) " +
" VALUES " +
" (" + user_id + " " +
" ,'" + tbFirstName.Text + "' " +
" ,'" + tbLastName.Text + "' " +
" ,'" + tbNickName.Text + "' " +
" ,'" + pictureFile + "' " +
" ,'" + tbUsername.Text + "' " +
" ,'" + tbPassword.Text + "')";
database.executeNonQuery(sql);
database.close();
Page.ClientScript.RegisterStartupScript(typeof(Page), "print", "<script type='text/javascript'> dialogWithRedirect('Save complete','user.aspx');</script>");
}
}
else
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "print", "<script type='text/javascript'> dialog('Please fill all required data');</script>");
}
}发布于 2014-02-25 21:15:41
我怀疑问题是在定义函数dialogWithRedirect和dialog之前,在后台代码中注册的脚本块被插入到页面中。要确保在调用这些函数时已经定义了它们,请将调用包装在加载回调中:
Page.ClientScript.RegisterStartupScript(typeof(Page),
"print",
"<script type='text/javascript'> $(function() { dialog('Please fill all required data'); });</script>");发布于 2014-02-26 12:37:43
或者你可以使用下面的代码
String PopUp="<script type='text/javascript'>"+"alert('Please fill all required data')"+"</script>");
Page.RegisterStartupScript("PopScript",Popup);我希望这能对你有所帮助。
https://stackoverflow.com/questions/22015066
复制相似问题