1

I have a User control and i have a method isDirty() added to this user control. This user control is used in many places.

How do i access this method using javascript .How do i create a javascript object for this particular user control and then access it with the find method ?

The $find('__The id of the user control ') ? I tried get null .???

Thanks & Regards, Francis

user581157
  • 1,327
  • 4
  • 26
  • 64

1 Answers1

0

js object is created like this:

var myobject = { prop1: 'hello', 
               prop2: function(){//whatever}, 
              prop3:'yay'};

myobject.prop1; //'hello'
myobject.prop2(); //that's right, it runs that function(){//whatever} in prop2

You cannot access any server side methods with JS directly. Make an AJAX request with a JSON object, parse it in ASP.NET, and in ASP.NET, call your function you want based on what it says in the object.

Flash can use ExternalInterface.addCallback to do a direct JS access but I am not sure ASP.NET has such a thing (and I would strongly recommend against using a "Flash's blackbox JS access" style anyway).

If you already added a JS object to your user control somehow server side by executing javascript, you just access it like this:

myUserControlAssociatedJSObject.myFunction(); //it runs it!
sajawikio
  • 1,516
  • 7
  • 12
  • Actually i want to access a Client side method say "IsDirty()" which is a part of the usercontrol using the $find component – user581157 Sep 10 '12 at 10:23
  • if isDirty() is already there as a JS function in a JS object, (check in Firebug DOM maybe you can find it) then you just do wherevermyJsObjectIs.isDirty() and bam you can run the function - hope this helps – sajawikio Sep 10 '12 at 10:24