1

in code behind :

    string func = "showSuccessMessage("+name+");";
    ClientScript.RegisterStartupScript(this.GetType(), "success", func, true);

in a js file :

   function showSuccessMessage(user)
   {
        $("#box").dialog({
            title:"User Registration",
            html: user.toString() + " Successfully Registered", 
            modal: true,
            buttons: {
                   Ok: function () {
                    $(this).dialog("close");
                    var s = "../Pages/main.aspx";                
                    window.location = s;
                   }
        }
   });
 } // end function 

when i try to pass the func string with no arguments every thing works out fine

when i try to append the argument into the function string i get an error from the browser

Uncaught ReferenceError: john is not defined

(john being the value of name) now i'm guessing the problem occurs because the way the function is registered it can't distinguish between a the variable and the value , so it is a non-defined type john

so the question stands :

how does one send arguments to a javascript function from code-behind

thanks in advance eran.

btw similar question : showing something similar to what iv'e attempted

similar question

1 Answer 1

2

The way you are writing it, it's like passing in john as a variable, not a string. It's like invoking

showSuccessMessage(john); // what you're doing in js
showSuccessMessage('john'); // what you need

Correct that with

string func = "showSuccessMessage('"+name+"');"; 
Sign up to request clarification or add additional context in comments.

1 Comment

10x allot , i knew that was the problem i just didn't think of putting ' ' .

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.