Click here to Skip to main content
15,888,133 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a textbox And TextboxdoubleClick Call script function
C#
txtBox.Attributes.Add("Ondblclick", "return clickButton(event, '" + btnSearch.ClientID + "')");

I am using the below script to call a button click in my usercontrol. But document.getElementById(buttonid) returns undefined
C#
<script type="text/javascript">
     function clickButton(event, buttonid) {
       
         var bt = document.getElementById(buttonid);
         if (bt) {
             bt.click();
         }
     }
Posted
Updated 13-Aug-13 2:13am
v2
Comments
Maarten Kools 13-Aug-13 8:16am    
At what time in the page life cycle to you add the attribute to your textbox? My guess would be that btnSearch.ClientID results in an empty string.
ZurdoDev 13-Aug-13 8:18am    
Isn't this a repost? Just view source on your page and find out what the actual rendered ID is and use that.
Ankur\m/ 13-Aug-13 8:19am    
What's the value of buttonid in clickButton function? Use firebug or VS debugger to find out and let us know.

Suggestion
Put a debugger like below...
XML
<script type="text/javascript">
     function clickButton(event, buttonid) {
         debugger;    

         var bt = document.getElementById(buttonid);
         if (bt) {
             bt.click();
         }
     }

Now, the execution will break at that point when you double click on TextBox.
Then, check the value of buttonid at this point by either hovering on it or putting it in watch of FireBug in FireFox.

Also check whether there is any element (with buttonid) present in the rendered html or not.
 
Share this answer
 
Comments
Member 8390746 14-Aug-13 1:32am    
The value of buttonid is "ctl00_ContentPlaceHolder1_txtLOV3_btnSearch"
But It is not firing the click event of btnSearch".When I am adding my usercontrol txtLOV in to a sample project its working. Now I am try to use this user control in my main project that contains a master page and inherits from custom Base Class.
Okay.

So, couple of questions for you...

Have you written any function for the click event of button?
Have you checked that the button is present inside the rendered html or not?

Check the console tab of FireBug in FireFox for all the errors and let me know.
Member 8390746 14-Aug-13 7:14am    
Yes I wrote a function in button click event,and I mentioned above the usercontrol is working perfectly in a sample project ,contains a default page and the user control, that i created to check the usercontrol, all script functions are running perfectly.Now I add this usercontrol in to main project then only the problems occurs.
Try keeping all the scripts inside the Master Page.
Member 8390746 14-Aug-13 7:19am    
I am also using the below script for textbox Keyup. Its working perfect

var to;
var prm = Sys.WebForms.PageRequestManager.getInstance(); // Page Request Manager object

function onTxtKeyUp(e, buttonid) {
// debugger;
if (e.KeyCode != 9)
to = setTimeout(function () {
performSearch(buttonid);
}, 300)
}
function onTxtKeyDown() {
if (to) clearTimeout(to);
}
function performSearch(buttonid) {

if (prm.get_isInAsyncPostBack) {
prm.abortPostBack();
}

__doPostBack(buttonid, "");

}
Hello,
Please try this,
Use btnSearch.StaticID instead of btnSearch.ClientID
txtBox.Attributes.Add("Ondblclick", "return clickButton(event, '" + btnSearch.StaticID + "')");
 
Share this answer
 
v3
Comments
Member 8390746 14-Aug-13 1:33am    
there is no StaticID

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