Click here to Skip to main content
15,904,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
I have some usercontrol texboxes Let us say DateControl on a page. I want to call a javascript function on onblur of one of these usercontrols. In that funcion I want to add some days in the entered value of usercontrol(Date Control Textbox). When i call javascript from usercontrol it doesn't work. my account is as follows;

<uc1:DateControl ID="DateControlLastExecDate"  runat="server"  önblur="javascript:CaluculateDate();"/>


So plz guide
Posted

Try adding the javascript to the Textbox on the usercontrol instead a datacontrol or usercontrol is not known in javascript and hence there is no "onblur" message sent in the first place (I think).

Tip: Load your page into IE and do a "view source" you'll see that your control has both a server id and a client id. you'll also get a good view on how the user control is integrated in the page. That might give you a better understanding on what to do.

Hope this helps.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 20-Jun-11 8:34am    
Good point! 5+
touseef4pk 20-Jun-11 8:44am    
If i add javascript in usercontrol then how will i fire javascript funcion on particular usercontrol(textbox) on onblur. The funciton will be fired on all textbox usercontrols placed more than one on the page?
V. 20-Jun-11 8:54am    
and what is the difference with your solution? Or did you intend to add multiple usercontrols in design mode and attach a different javascript function?
RakeshMeena 21-Jun-11 0:22am    
Correct! fully agree and here is my 5
touseef4pk 21-Jun-11 2:10am    
The user control renders as ctl00_contentBody_DateControlLastExecDate_textBoxDate on the page....So my solution is I simply want that javascript function to be fired on this particular usercontrol(textbox) leave only..not on all the controls if they placed more than one..Ok if i add javascript function in usercontrol..Plz tell me how to handle that on contaning page?

  1. The event is called onblur and not önblur.
  2. Is your javascript function really called CaluculateDate? Shouldn't that be more like CalculateDate?
  3. Added: As V.[^] correctly pointed out: You have defined the usercontrol so in order to get the javascript event working you'd have to wire up the onblur event on some HTML part of your control that would suport such an event before it gets rendered.


Cheers!

--MRB
 
Share this answer
 
v6
Another way is to add the javascript's function to the Text control's onBlur attribute.

Example :

In your code behind, you may do this

C#
protected void Page_Load(object sender, EventArgs e)
       {
           this.txtName.Attributes.Add("onBlur", "return CalculateDate();");
       }


:-)
Balaji
 
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