Folks....can u tell me how to pass an argument to the Javascript function written in source thru Code behind...??

here is my code:

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function message(name)
    {
    alert("Hello" + name)
          }
    
    </script>
</head>

In my code behind file :

btnok.Attributes.Add("Onclick", "message();"); // HOW TO PASS
ARGUMENT TO THIS FUNCTION MESSAGE ?? SO THAT WHEN USER ENTERS THE NAME IN TEXT BOX EG. CHARLIE....AND CLICK ON OK 
IT SHOULD GIVE OUTPUT HELLO CHARLIE ??

SECONDLY , IF I CLICK ONCE MY FUNCTION DOES NOT GET EXECUTED , I NEED TO CLICK 2 TIMES WHY SOOO ?? 

AWATING REPLY.

CYA
ROHAN

Hi,
You can directly pass it in the function paranthesis.
see the code below

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function message(name)
    {
    alert("Hello" + name)
          }

    </script>
</head>

In my code behind file :

btnok.Attributes.Add("Onclick", "message(textbox1.text);");

Does it really words ? 'coz i think it recognises the textbox1.text as string ?
have u tried using it n r u getting the output...? pl let me know...'coz i am getting error !

cya
Rohan

Hi,
You can directly pass it in the function paranthesis.
see the code below

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function message(name)
    {
    alert("Hello" + name)
          }

    </script>
</head>

In my code behind file :

btnok.Attributes.Add("Onclick", "message(textbox1.text);");

end quote.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.