S B  Ray

S B Ray

  • NA
  • 11
  • 0

showing a window.confirm message and get its return value

Nov 12 2007 2:30 AM
Hi,

I am having a web page in which there is a textbox and a button.The Button is a web server control and it is used to create servers.A server is nothing but a folder which is created in the web server root and it contains several files.Now the code for the "Create Server" button is as follows:

private string DoCreate()
    {
     
          string strpath;
        string status;
        txtbox1val = TextBox1.Text.Trim().ToString().ToUpper();
        strpath = Server.MapPath(Request.ApplicationPath) + "\\" + txtbox1val;
        //Response.Write("SERVER ROOT: " + strpath);
        //if(eventArgument == Convert.ToString(1))
        //{
        if (Directory.Exists(strpath))
        {
            Label10.Text = "The name " + txtbox1val + "already exists.Pls choose a different one";
            status = "failure";
            return status;

        }
        else
        {
            try
            {
                //create the directory


                Directory.CreateDirectory(strpath);
                Session["Path"] = strpath;
                //Label10.Text = "Success ! Server Created";
                TextBox3.Text = txtbox1val;
                txtfolderpath.Text = "SERVER ROOT";
                TextBox1.ReadOnly = true;
                TextBox3.ReadOnly = true;
                txtfolderpath.ReadOnly = true;
                return TextBox3.Text.ToString();
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();

            }
        }
    }

But before the Directory is actually created I want a window.confirm(' Are u sure to create a server?If yes press OK') to pop up on pressing the button. Then if the user presses OK the above function is called to create the server.

For poping the window .confirm() I used the following code:

protected void Page_Load(object sender, System.EventArgs e)
        {
            string msg = "function Hello() {var r = confirm('Are u sure to create a new Server.If yes press OK');if(r==true){//call code behind function}}";

            ClientScript.RegisterStartupScript(this.GetType(), "myScript", msg, true);
            Button3.Attributes["onclick"] = "Hello()";

            //sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "ShowResult", "context", true);
         }
But this code is not working now.Now a IE window comes up but with  a 'asterik' on the lower left corner showing error. This code worked the first time I used it ,but subsquently I tried sevral different things like Client Callback etc but nothing worked. finally this had also stoopped working. The error shown by I E is non existent bec' you don'tfind any error in the line number it shows.However if the line
ClientScript.Register....  is commented then the error goes.

So how do I get it to work and how I get the return value? If the return value is "OK" then the DoCreate() function is to be called and executed.

Thanks in advance.Expecting a complete solution to problems like these.

Answers (2)