0

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
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by laghaterohan
0

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);");

Edited by mike_2000_17: Fixed formatting

0

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.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.