473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

'this' keyword causing some problem (ASP.NET and Javascript)

83
In my web page I have a linkbutton with onClientClick event as show below.
Expand|Select|Wrap|Line Numbers
  1. <asp:LinkButton ID="lnkbtn" Text="Click" runat="server" OnClientClick="dosomething(this.Text)"></asp:LinkButton>
  2.  
And I've defined the function as shown below in the head section of the webpage

Expand|Select|Wrap|Line Numbers
  1. function dosomething(ObjCntxt) 
  2.   var textval = ObjCntxt;
  3.   alert(textval); 
  4.  
When I run the page and click on the LinkButton I'm getting the message 'undefined'.

I request you all kindly solve my problem.

Thanks & Regards,

BTR.
Nov 26 '10 #1
1 1520
Frinavale
9,735 Expert Mod 8TB
In JavaScript, there is no "Text" property for a hyperlink (which is what a LinkButton rendered as).

For example, your LinkButton:
<asp:LinkButton ID="lnkbtn" Text="Click" runat="server" OnClientClick="dosomething(this.Text)"></asp:LinkButton>

Will be rendered as this in HTML:
<a id="lnkbtn" name="lnkbtn" href="javascript:__doPostback('lnkbtn','');" onclick="dosomething(this.Text)">Click</a>

Since there is no "Text" property for a hyperlink, pass this.innerHTML to the JavaScript method "dosoemthing" instead. The innerHTML property will pass whatever is within the opening <a> and closing </a> tags....which is your Text.

Like this:
<asp:LinkButton ID="lnkbtn" Text="Click" runat="server" OnClientClick="dosomething(this.innerHTML)"></asp:LinkButton>

-Frinny
Nov 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
6
by: Graeme Wood | last post by:
I have an ASP page hosted on a windows 2003 server. This page was working fine until Saturday. Now, the server doesn't serve it and gives a 404 page not found error. The file DEFINITELY exists...
1
by: Whitney | last post by:
On the left side of the main webpage I have some menu options that have a drop-down feature that is controlled with javascript. You click on the main heading and the links for that section show up....
5
by: Water Cooler v2 | last post by:
Does the *this* keyword refer to the class or the instance?
3
by: Dave | last post by:
Hi, I need a little help in understanding why FxCop complains about this. If I have a basic class like: class Class1 { static void Main()
5
by: Martin Walke | last post by:
Hi all, Can someone help me out here? I'm been using ASP and VBScript for some years but have just ventured into the realms of using server side Javascript and apart from hitting various...
4
by: zfarooq01 | last post by:
Asp Javascript language paging larger database record sets i am firmiliar with asp javascript and not asp VB. i can display the results ok, but if i return 100 records from my table i would...
1
by: ceolino | last post by:
Hi all. I have a simple default.aspx file where I declare a JavaScript function: <script type="text/javascript" language="JavaScript"> .... function rotate() { .... } </script>
2
by: mrjoka | last post by:
hi experts, i'm developing a page in ASP but i'm doing also some javascript insode the page. i'm creating a frame and i want to loop this frame with a duplicateloop function so the form will be...
5
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.