开发者

Simple ASP.Net MessageBox?

开发者 https://www.devze.com 2022-12-12 10:51 出处:网络
I want a simple MessageBox for ASP.Net, but everything I tried didn\'t work and I don\'t know why. The last thing I tried was this but it didn\'t work either.

I want a simple MessageBox for ASP.Net, but everything I tried didn't work and I don't know why. The last thing I tried was this but it didn't work either.

Any ideas for a simple messagebox with work safe?

For more information:

  • I can't bind anything to a开发者_JAVA技巧 button
  • I must call it from the Code Behind
  • Directly after clicking okay, I must have a redirect

Test it with onClick on the button:

                    string msg = "Text";
                    string script = "<script language=JavaScript>alert("+msg+");</script>";
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", script);

but it doesn't work


You could use the dialog component from jQuery UI to display a message box. A simple usage demo is available here.


Here is your answer.

http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx

protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
string s = "here in button event";
            string script = "<script language=JavaScript>alert('" + s + "');</script>";
            if (!Page.ClientScript.IsStartupScriptRegistered("clientScript"))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", script);
        }

        }


        }


Is this using ajax? Is this attached to a server side event that's called when the user clicks a button?

If so, ajax only sends data that's associated with the updatepanel in question. If so, try this ScriptManager.RegisterStartupScript((Control)ctlControl, ctlControl.GetType(), "ClientScript", "alert('foo')", true); It is important that the ctlControl is inside the updatepanel being updated.

If you are not using ajax, is ClientScript registered elsewhere with RegisterClientScriptBlock? The client name has to be unique for every registry or it will think you are calling the same code twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消