C# Tutorials and offshore development in India

Tutorials Resources Forum Reviews Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...




Forums » .NET » ASP.NET »

Linkbutton text


Posted Date: 24 Apr 2009      Posted By: Elz      Member Level: Gold     Points: 1   Responses: 6


The status of this forum is Deleted.


Hi all,

I wrote a javascript function and i call on the click event of linkbutton(LinkButton2).I want the text of that linkbutton .How to achieve using javascript?Anyone pls give a solution.
Thanks

<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="Name" SortExpression="P_NAME">
<ItemTemplate>
<img src="images/open.gif" />
<asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:return addtab();" CausesValidation="false"
CommandName="name" Text='<%# Eval("[ name]") %>' CommandArgument='<%# Eval("[Id]") %>'></asp:LinkButton>

</ItemTemplate>
</asp:TemplateField>
</asp:GridView>


<script language="javascript" type="text/javascript">
function addtab(){

alert("begin");
var tabctrl1 = window.parent.igtab_getTabById("Tab2");
tabctrl1.Tabs[2].setEnabled(true);
tabctrl1.Tabs[2].setVisible(true);
var b = document.getElementById("LinkButton2");
alert(b.innerText); //this not working
alert("end");

}
</script>





Responses

Author: Anil Kumar Pandey    24 Apr 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,

u can use either b.value or b.Text


<script language="javascript" type="text/javascript">
function addtab(){

alert("begin");
var tabctrl1 = window.parent.igtab_getTabById("Tab2");
tabctrl1.Tabs[2].setEnabled(true);
tabctrl1.Tabs[2].setVisible(true);
var b = document.getElementById("LinkButton2");
alert(b.Text); or alert(b.value);
alert("end");

}
</script>



Thanks & Regards
Anil Kumar Pandey



Author: :) Bob (:    24 Apr 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

hai...

<asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:return addtab();" CausesValidation="false"
CommandName="name" Text='<%# Eval("[ name]") %>' CommandArgument='<%# Eval("[Id]") %>'></asp:LinkButton>

Above is ur code. In that code you are calling a javascript on client click. Pass the text as argument to this function. the correct code is below

<asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:return addtab(this);" CausesValidation="false"
CommandName="name" Text='<%# Eval("[ name]") %>' CommandArgument='<%# Eval("[Id]") %>'></asp:LinkButton>

function addtab(TXT)
{
alert(TXT)
}
another method is

function addtab(ID)
{
alert(ID.innerHTML)
}

2nd one i am not sure, is it correct or not


Bobbin



Author: Dotnet Galaxy    24 Apr 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi suze,

Do the following,
1. Create a following javascript function to get the linkbutton text.


function GetLinkButtonText()
{
var lnk=document.getElementById('LinkButton1');
alert(lnk.innerText);
return false;
}



2. Create a LinkButton control and call the javascript function like following,


<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return GetLinkButtonText();">Sample Text</asp:LinkButton>


3. Thats it. It will return a linkbutton text.

Hope it helps. Happy Coding...

Thanks,
DotNet Galaxy.

*******************************************
Note - Please rate this response [Poor / Fine / Good / Great / Excellent]
*******************************************



Author: Elz    24 Apr 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Thanku i vl check it


Author: Techie    24 Apr 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

try this way,

function addtab()
{

b = document.getElementById("<%=LinkButton2.ClientID%>");
alert(b.innerText);

}



Author: Miss Meetu Choudhary    18 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

duplicate post deleted

Thanks and Regards
Miss Meetu Choudhary (Site Coordinator)
Go Green Save Green
http://www.jaipurmentor.com/
My Profile on Google



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Popup window
Previous : String was not recognized as a valid datetime - this error occurs in server
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages




About Us    Contact Us    Privacy Policy    Terms Of Use