Solved

Calling javascript with ClientID

Posted on 2014-01-10
4
347 Views
Last Modified: 2014-01-12
I have an asp text box that sits within a gridview. I would like to call a javascript method OnBlur and pass the ClientID of the textbox to the javascript method. How to do. Below is my markup. Any help would be much appreciated. Code below does not seem to work.

<asp:TextBox ID="txtInsertUnitRCVEmpty" TabIndex="81"  OnBlur="javascript:checkforvalidation('<%= txtInsertUnitRCVEmpty.ClientID %>');" onkeydown="return isNumber(event);"   Width="100px" runat="Server" Text="0.00"></asp:TextBox>


Jason
0
Comment
Question by:jazzcatone
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 167 total points
Comment Utility
Pass the object using this

<asp:TextBox ID="txtInsertUnitRCVEmpty" TabIndex="81"  OnBlur="javascript:checkforvalidation(this);" onkeydown="return isNumber(event);"   Width="100px" runat="Server" Text="0.00"></asp:TextBox>

In your function you can then access its properties e.g.

function checkforvalidation(elem){
     alert(elem.id)
}
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 167 total points
Comment Utility
replace : OnBlur="javascript:checkforvalidation('<%= txtInsertUnitRCVEmpty.ClientID %>');"
by : onblur="checkforvalidation(this.id);"
0
 
LVL 16

Assisted Solution

by:Kamal Khaleefa
Kamal Khaleefa earned 166 total points
Comment Utility
hi
you can solve this by binding it through grid view row data bound

ex:
  If e.Row.RowType = DataControlRowType.DataRow Then




            Dim MyTextBox As TextBox = e.Row.Cells(3).Controls(1)
'you can change this e.Row.Cells(3).Controls(1) to find the control


            If Not MyTextBox Is Nothing Then
                MyTextBox .Attributes.Add("OnClick", "javascript:checkforvalidation(" & MyTextBox.ClientID& ");")
 

            End If
        End If

Open in new window

0
 

Author Closing Comment

by:jazzcatone
Comment Utility
Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now