Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 8-Jan-13 1:01am
gunaaa525
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick='<%# string.Format("javascript:return test(\"{0}\")", Eval("DocumentDescription")) %>' />
  Permalink  
Comments
gunaaa at 8-Jan-13 7:18am
   
Thanks for your reply.
Its working fine...
gunaaa at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

OnClientClick='<%# string.Format("javascript:return fnSelectedLocationList(\"{0},{1},{2},{3},{4}\")", Eval("Location"),Eval("Version"),Eval("Lot"),Eval("Quantity"),Eval("WKOLineNumber")) %>'
  Permalink  
Comments
gunaaa at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this:
 
<asp:LinkButton ID="lnkTest" runat="server" Text="Click" OnClientClick="<%# String.Concat("test(", Eval("DocumentDescription"))) %>"/>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<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:
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;
}
  Permalink  
v3
Comments
gunaaa at 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 at 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 at 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 at 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?
SureshDasari1986 at 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")) %>'
gunaaa at 8-Jan-13 7:59am
   
Thanks for your reply...
Zafar Sultan at 8-Jan-13 7:44am
   
You should not call two javascript functions using onlcientclick = "HideHelpWin();ShowHelpWin('AddAlert');". Instead create a single javascript function, pass all the parameters and then within that single function call HideHelpWin();ShowHelpWin('AddAlert'); and whatever functions you want to use. And to pass multiple parameters to your JS function refer the above comment by SureshDasari1986.
gunaaa at 8-Jan-13 7:59am
   
ok thanks for your explanation. I will use only one javascript function...
gunaaa at 8-Jan-13 8:03am
   
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?
Zafar Sultan at 8-Jan-13 8:32am
   
Check my updated reply. Give it a try and then tell is it working?
gunaaa at 9-Jan-13 0:01am
   
Hi Zafar Sultan,
Thank you. Its working fine. My coding is below
function ShowHelpWin(obj1, obj2, obj3) {
HideHelpWin();
BubbleClick(obj1);
overdi(obj2, 'divAddAlert', 'BottomLeft', 30, 920);
}
<asp:LinkButton ID="lnkAddAlert1" runat="server" Text="Add Alert" CssClass="Link09"
CommandName="AddAlert" OnClientClick='<%# string.Format("javascript:return ShowHelpWin(event,this,\"{0}\")", Eval("DocumentDescription")) %>'>

 
Its working fine now....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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

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

  Print Answers RSS
0 CPallini 375
1 Sergey Alexandrovich Kryukov 262
2 OriginalGriff 225
3 George Jonsson 114
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 19 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100