Solved

Calling javascript with ClientID

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now