最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Javascript alert box invoked from codebehind does not work - Stack Overflow

programmeradmin2浏览0评论

I need alert boxes to let the user know of successful entry or data conflicts. I've tried the following and I get no errors and no alerts.

In the Save_Click:

    ClientScript.RegisterStartupScript
    (GetType(), "Javascript", "javascript: UpdateComplete(); ", true);

also...

    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript",
    "<script>alert('Record Added Successfully')</script>");

also...

    Save.Attributes.Add("onclick","return ReqField1Validator()");

I've used GetType and TypeOf both.

    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "alert", "alert('See me?');", true);
    return;

I've also tried the very popular suggestion

    Response.Write("<script>alert('Hello');</script>");

and nothing works. I've tried many variations on these, moved them to the Updated method and the click method and all over and nothing ever happens.

Can anyone tell me what I'm doing wrong or what I'm overlooking? Thanks for your time and patience.

I need alert boxes to let the user know of successful entry or data conflicts. I've tried the following and I get no errors and no alerts.

In the Save_Click:

    ClientScript.RegisterStartupScript
    (GetType(), "Javascript", "javascript: UpdateComplete(); ", true);

also...

    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript",
    "<script>alert('Record Added Successfully')</script>");

also...

    Save.Attributes.Add("onclick","return ReqField1Validator()");

I've used GetType and TypeOf both.

    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "alert", "alert('See me?');", true);
    return;

I've also tried the very popular suggestion

    Response.Write("<script>alert('Hello');</script>");

and nothing works. I've tried many variations on these, moved them to the Updated method and the click method and all over and nothing ever happens.

Can anyone tell me what I'm doing wrong or what I'm overlooking? Thanks for your time and patience.

Share Improve this question asked May 10, 2013 at 16:45 R_ScottR_Scott 1433 silver badges14 bronze badges 2
  • where you are writting these codes – Amit Singh Commented May 10, 2013 at 16:49
  • 2 Is there a pop up blocker blocking it? – epascarello Commented May 10, 2013 at 16:49
Add a ment  | 

1 Answer 1

Reset to default 5

here buddy,

  string script = "alert('its working now!')";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "its working", script, true);

just tested it now and guarantee its working

regarsd

发布评论

评论列表(0)

  1. 暂无评论