Solved

Calling javascript with ClientID

Posted on 2014-01-10
4
350 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

778 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