Click here to Skip to main content
15,885,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass gridview value to javascript function.
But it shows an error.

My code is below:

<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick="javascript:test('<%# Eval("DocumentDescription")%>')">

What is wrong with it?
Posted

<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick='<%# string.Format("javascript:return test(\"{0}\")", Eval("DocumentDescription")) %>' />
 
Share this answer
 
Comments
gunaaa 8-Jan-13 7:18am    
Thanks for your reply.
Its working fine...
gunaaa 8-Jan-13 7:36am    
I have another doubt. I want to pass multiple parameter to javascript. My code is below:
<asp:LinkButton ID="LinkButton2" runat="server" Text="Add Alert"
OnClientClick="HideHelpWin();ShowHelpWin('AddAlert');return false;">

I want to add "Eval("DocumentDescription")" these value to set an another parameter to ShowHelpWin javascript function. Can you please help me?
OnClientClick='<%# string.Format("javascript:return fnSelectedLocationList(\"{0},{1},{2},{3},{4}\")", Eval("Location"),Eval("Version"),Eval("Lot"),Eval("Quantity"),Eval("WKOLineNumber")) %>'
 
Share this answer
 
Comments
gunaaa 8-Jan-13 8:15am    
In my project i am using like this <asp:LinkButton ID="lnkAddAlert" runat="server" Text="Add Alert" CssClass="Link09" CommandName="AddAlert" OnClientClick="HideHelpWin();BubbleClick(event);overdi(this,'divAddAlert','BottomLeft',30,920);ShowHelpWin('AddAlert');return false;"> at this situation how to call single javascript funtion? and i want to call multiple parameter to ShowHelpWin() function which i have explained previously?
try this:

<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick="<%# String.Concat("test(", Eval("DocumentDescription"))) %>"/>
 
Share this answer
 
ASP.NET
<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick='<%# string.Format("javascript:YourJavascriptFunction(\"{0},{1},{2},{3},{4},{5}\")","window.event", Eval("FirstParameter"),Eval("SecondParameter"),Eval("ThirdParameter"),Eval("FourthParameter"),Eval("FifthParameter")) %>')"


Javascrip Function:
JavaScript
function YourJavascriptFunction(e,firstParameter,secondParameter,thirdParameter,fourthParameter,fifthParameter)
{
//Use 
//e,firstParameter,secondParameter,thirdParameter,fourthParameter,fifthParameter 
//here

HideHelpWin();
BubbleClick(e);
overdi(this,'divAddAlert','BottomLeft',30,920);
ShowHelpWin('AddAlert');
return false;
}
 
Share this answer
 
v3
Comments
gunaaa 8-Jan-13 7:19am    
Correct format is below:
<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick='<%# string.Format("javascript:return test(\"{0}\")", Eval("DocumentDescription")) %>' />
Zafar Sultan 8-Jan-13 7:27am    
Now that you know what is the correct format, can you also state what is wrong with: <asp:linkbutton id="lnkTest" runat="server" text="Click" onclientclick="javascript:test('<%# Eval("documentdescription")%>')" />?
gunaaa 8-Jan-13 7:38am    
If i use these code <asp:linkbutton id="lnkTest" runat="server" text="Click" onclientclick="javascript:test('<%# Eval("documentdescription")%>')" /> it shows an error.
Error: The server tag is not well formed.
gunaaa 8-Jan-13 7:39am    
I have another doubt. I want to pass multiple parameter to javascript. My code is below: <asp:LinkButton ID="LinkButton2" runat="server" Text="Add Alert" OnClientClick="HideHelpWin();ShowHelpWin('AddAlert');return false;"> I want to add "Eval("DocumentDescription")" these value to set an another parameter to ShowHelpWin javascript function. Can you please help me?
Suresh Dasari's 8-Jan-13 7:42am    
OnClientClick='<%# string.Format("javascript:return fnSelectedLocationList(\"{0},{1},{2},{3},{4}\")", Eval("Location"),Eval("Version"),Eval("Lot"),Eval("Quantity"),Eval("WKOLineNumber")) %>'
try:

<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick='<%# String.Format("test(""{0}"")", Eval("DocumentDescription")) %>'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900