开发者

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 开发者_如何学Go="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?


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...


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.


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜