Home > Back-end >  passing string value in Linkbutton onclientclick in Eval in grid while calling javascript function
passing string value in Linkbutton onclientclick in Eval in grid while calling javascript function

Time:12-10

I want to pass string value in Eval while passing value in JavaScript function. It is working perfect for integer value, but for string values it is not working. Please find my code below:-

<asp:LinkButton ID="btnVCharge" runat="server" Text='<%# Eval("Name") %>'  OnClientClick='<%# "test("   Eval("Id")   ","   Eval("Name")   ");" %>'></asp:LinkButton>

I also tried to convert to string using Eval("Name").ToString() but without any success

My javascript function:-

  function test(id,name) {
            alert(id);
            alert(name);
        }

I am getting a javascript error:

Uncaught ReferenceError: 

Thank you

CodePudding user response:

I did it using changing Link button to Hyperlink

<asp:HyperLink ID="hlCharge" runat="server" Text='<%# Eval("Name") %>' onclick='<%# "test("  Eval("Id")   " ,"   "\""   Eval("Name")   "\""   ");" %>' ></asp:HyperLink>
  • Related