Solved

Calling javascript with ClientID

Posted on 2014-01-10
4
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 167 total points
ID: 39772590
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
ID: 39774109
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
ID: 39774285
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
ID: 39775719
Thank you
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

687 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