.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Get Linkbutton Text Value from link button in Grid view

Posted By: bhanu     Posted Date: November 24, 2010    Points:2   Category :ASP.Net
I have a link button thats text value is populated from a dataset value retrieved from a database. When the user clicks on this link button I want to somehow capture the text value. The trick is the linkbutton is within a usercontrol, and I want to do the processing from the user controls parent.

I may be able to do this via javascript with the OnClientClick;




<asp:TextBox ID="txtmobile" runat="server" Width="239px" TextMode="MultiLine"></asp:TextBox>

Enter Mobile numbers seperated by commas.



<asp:GridView ID="GridView1" runat="server" GridLines="Horizontal" AutoGenerateColumns="False"

PageSize="3" EmptyDataText="No Companies Found" BorderWidth="1px" AllowPaging="True"

OnPageIndexChanging="GridView1_PageIndexChanging" ShowHeader="False" Width="100%" >

<RowStyle BorderStyle="None" BorderWidth="1"></RowStyle>




<asp:LinkButton ID="LinkButton1" runat="server" Style="padding: 5px 5px 5px 5px;

float: left;" Text='<%#Eval("defaultmsg")%>' OnClientClick='<%#DataBinder.Eval(Container.DataItem,"defaultmsg","return test(\"{0}\")")%>'>






<asp:LinkButton ID="LinkButton1" runat="server" Style="padding: 5px 5px 5px 5px; float: left;" Text='<%#Eval("defaultmsg")%>' OnClientClick='<%# DataBinder.Eval(Container.DataItem,"defaultmsg","return test(\"{0}\")")%>'>
When the link button is clicked in the gridview i want the link button text will be assigned to the textbox which is present outside of the gridview.for this iam using databinder.with the datbinder iam getting the text.. but when the text contains some special charcters doublequotes iam facing the problem unterminated string literal or syntax error in the console of firebug..iam not getting the linkbutton text..

The test function is like this

function test(id) {

document.getElementById("<%=txtmsg.ClientID%>").value = id;

var m = "140";

var len = document.getElementById("<%=txtmsg.ClientID%>").value.length;

var str = document.getElementById("<%=txtmsg.ClientID%>").value;

if (len <= m) {

document.getElementById("<%=txtremchars.ClientID%>").value = m - len;


else {

document.getElementById("<%=txtmsg.ClientID%>").value = str.substr(0, str.length - 1);


return false;


When iam using the above code iam facing problem with double quotes i think..the error in the console is

unterminated string literal or syntax error with some text like

return test("G|'\ |"'| U| |\ \_| I G ...\____| HvE NiCe slEepY Gud nYt!!!");

please help me as early as possible


No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend