0

i want to open a model pop up on some button click in code behind which has got a few if else condition. First of all i am unable to fix what would be best approach. What i options i think are followign. 1) calling a jquery model pop up 2) ajax model pop up

It is a button which fix on some button click condition to open the model pop up, if model pop says yes then, i want client to rediret to some payemnt page where he will pay to purchase the item.

Right now i am using the Jquery model pop up which i am calling like this

 protected void imgClientFreeEval_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
-----
---some code not typed
 if (SurveyCount > 1)
            {
                Session["YourAssessment"] = true;
                Session["MyAssessment"] = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);
                //Response.Redirect("~/yourAssessment.aspx");

            }
}

and i have model pop up like this

 function xyz() {
            //  alert('hi tpo all');
            // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
            //            $("#dialog:ui-dialog").dialog("destroy");
            $(document).ready(function () {
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 140,
                    modal: true,
                    autoOpen: false,
                    buttons: {
                        "OK": function () {
                            $(this).dialog("close");
                            window.location.replace("http://stackoverflow.com");

                        },
                        Cancel: function () {
                        window.location.replace("http://stackoverflow.com");
                            $(this).dialog("close");
                        }
                    }
                });
            });
        }

Now the problem is that this function not getting called at all. what is wrong with this, i am toiling for long, if possible please suggest me best approach how should i execute it. i am unable to call this javasccipt function from code behind button click.

2
  • Which function is not being called?? Commented May 21, 2012 at 12:13
  • function xyz(), i simply want to do an alert kind of thing that will fix on yes no condition where to redirect. Commented May 21, 2012 at 12:20

4 Answers 4

1

The method I use to get javascript alerts up from my codebehind is like this:

public void AMessage(string message)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "info only", "alert('" + message + "');", true);
}

If you aren't using the OnClientClick event in your button, then send the message through a similar handler. In your case, instead of calling "alert('" + message + "');" call the function you have written.

Sign up to request clarification or add additional context in comments.

8 Comments

as you mentioned, can i do alert like this that if ok then redirect to some page if cancel then redirect to some other page? i am not using onclientclick
No reason why you shouldn't be able to. As you have done, you have constructed the script in the code behind, if you are using a confirm, then the javascript event handling should be able to redirect in the normal manner. Just handle the response from the confirm within the script you pass to the ScriptManager.
Just to add to that though, make sure you have all the semi-colons and so on correct in the script manager parameters - its very easy to drop one. Personally, I would think about constructing the script as a string in another method, fetching the script as a string variable then passing that variable into the ScriptManager. Would make it easier to debug as well.
NO NOT GETTING CALLED..I JUST DONT UNDERSTAND, I HAVE BEEN TOILING FOR LONG
Have you managed to debug the actual script you want to run? For example, pull it into a .js file of its own and run it with supplied parameters. Make sure the base script is working, then build on it.
|
0

if you want to get alert and then redirect your page when OK is clicked. you can try like :

ClientScript.RegisterStartupScript(this.GetType(), "My alert", "alert('" Your time has been finished "');", true);
    System.Text.StringBuilder sbs = new System.Text.StringBuilder();
    sbs.Append("<script language='javascript'>");
    sbs.Append("window.location = 'http://www.google.com/'");//or whatever you want:-
    sbs.Append("</script>");
    Type tr = this.GetType();
    ClientScript.RegisterClientScriptBlock(tr, "PopupScript2", sbs.ToString());

2 Comments

i wan to have ok-Cancle kind of functionality, that i can have in model pop up only i suppose, on on cancel i want to redirect to other page.
same approach you can follow for that also.
0

Try using this :

function xyz() {
            //  alert('hi tpo all');
            // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
            //            $("#dialog:ui-dialog").dialog("destroy");
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 140,
                    modal: true,
                    autoOpen: false,
                    buttons: {
                        "OK": function () {
                            $(this).dialog("close");
                            window.location.replace("http://stackoverflow.com");

                        },
                        Cancel: function () {
                        window.location.replace("http://stackoverflow.com");
                            $(this).dialog("close");
                        }
                    }
                });
            });
        }

Comments

0

One problem that I noted in your code is that in the line:

ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);

You are passing last parameter as true, which is addScriptTags, but you are already adding the script tag in the call, so might be it is creating problem over there.

Cheers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.