Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add onclick method to textbox inside grid.In this scenerio i can bind the client id the get the value of that grid item inside javascript method or can bind directly the value to the javascript method which is the best way for implementation



1. binding the client id and getting the value
txtbx1.attributes.add("onclick","Getvalues('txtbx1')");

If i am passing id javascript will search complete html,so performance will be less


2. Bind value directly to the method
txtbx1.attributes.add("onclick","Getvalues('20')");

No need to search get the value directly performance will be good

My answer is 2 .Please suggest your answers
Posted
Updated 20-May-14 2:20am
v2
Comments
[no name] 20-May-14 8:10am    
If you already know the answer, then why are you asking?
Srikanth954 20-May-14 8:15am    
No i implemented the second one as per the performance i want to confirm whether my assumption is correct.please answer your view
[no name] 20-May-14 8:28am    
Why? You asked and answered your own question so there is nothing here to give an answer to. And this is not a proper place to perform code reviews IMO.
Srikanth954 20-May-14 8:32am    
Not like that i did the code and hosted in live environment.It is working fine but just my doubt is whether my assumption is correct or not.It should fail in any cases.
[no name] 20-May-14 8:58am    
So in other words, you are obsessing about a non-existent problem?

1 solution

You're doing Option.1 in wrong way. You were sending only control id to javascript function. I think you're creating object there to get value from textbox after matching the element. That's why the slow.

Here better way(than existing one). I'm just getting the value & sending to javascript function.
C#
txtbx1.attributes.add("onclick","Getvalues('" + txtbx1.Text + "')");

One more suggestion(alternative).
Go with jQuery instead of javascript. Using Click()[^] event you could reduce the code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900