happysmile
happysmile

Reputation: 7777

How to send an value from .aspx page to JavaScript file?

I have these functions:

function clear(txtvalue)
{

}

function EnableValue (txtvalue, rfvValue)
{

}

    <asp:Button ID="btn1" runat="server" OnClick="btn1_Click" onclientClick =" return clear('"+txtValue.ClientID+'"); Text="Button" />

<asp:Button ID="btn2" runat="server" OnClick="Button1_Click" onclientClick ="return EnableValue ('"+txtValue.ClientID+'",'"+rfvValue.ClientID+'")"; Text="Button" />

I have two functions where I am trying to send an value from my .aspx page (button) to a JavaScript file.

I get an error telling server tag is not well formed.

What is the issue here?

Upvotes: 0

Views: 1144

Answers (3)

ACP
ACP

Reputation: 35268

Hai prince,

"return clear('" + txtValue.ClientID + "');"

"return EnableValue ('" + txtValue.ClientID + "','" + rfvValue.ClientID + "');"

and see what happens whether you can get value of it in javascript function...

Upvotes: 2

Codewerks
Codewerks

Reputation: 5972

Aside from the messy concatenation, your quotes are messed up. Make sure your javascript ";" is inside the double quotes for onclientClick.

<asp:Button ID="btn1" runat="server" OnClick="btn1_Click" onclientClick =" return clear('" + txtValue.ClientID + "');" Text="Button" />

<asp:Button ID="btn2" runat="server" OnClick="Button1_Click" onclientClick ="return EnableValue ('" + txtValue.ClientID + "','" + rfvValue.ClientID + "');" Text="Button" />

Upvotes: 0

Eren
Eren

Reputation: 284

You should try to set the OnClientClick property in the code side. You try to concatenate strings while defining a server tag, which is unusual. You can add that line to your Page_OnLoad method:

btn1.OnClientClick = "return clear('" + txtValue.ClientID + "');";

...and pay extra attention to quotation marks, they were wrong in the code you supplied, they should be written like the one above.

Upvotes: 0

Related Questions