0

how can I run $(document).ready(function () { ....

function inside the user controlI am dynamically load my use control,what I wanan do is that whenthe load usercontrol,register my some javascript function via ready function.

here is the my javascript inside the my usercontroler,

<script language="javascript" type="text/javascript">

    //register this script when the page load

        var MainFunction;
        $(document).ready(function () {

            MainFunction = function (Plaka) {
                alert(Plaka);



            }

        });

    </script>

and I amtring to call Main function via my button which is the sam place of the ready function inside the usercontroler.

  <ext:Button runat="server" ClientIDMode="Static" ID="btnMusteriEkle" Text="Yeni müşteri ekle">
                      <Listeners>
                       <Click Handler="MainFunction(#{txtPlaka}.getValue())">  </Click>
                       </Listeners>
                      </ext:Button>

I am trying to call MainFunction(#{txtPlaka}.getValue()) like this but not working.I am getting the error MainFunction is not defined.

emmm noone help me??!

sakir
  • 3,391
  • 8
  • 34
  • 50

1 Answers1

0

here is the solution I found;

inside the user control define this ,

   $(document).ready(function () {
        $('#btnEkle').click(myFunction); //binding button evet to function on the sam epage

    });

secondlly ,define this function inside the main page.

 function myFunction(Param1,Param2) {
        alert(Param1+''+Param2);
    }

I guess this work soemthing like this(Pls correct me if I am wrong). first load main page with the registered function, later when the loading user control first time run the this part;$(document).ready(function () {,later ,this function registerd the button event.

button:

  <ext:Button runat="server" ClientIDMode="Static" ID="btnMusteriEkle" Text="Yeni müşteri ekle">
                      <Listeners>
                       <Click Handler="myFunction(#{Param1}.getValue(),#{Param2}.getValue()
                     )">  </Click>
                       </Listeners>
                      </ext:Button>

**if u tried this making stupid asp.net button,all pages after fire event render again iu will get the undefine value. as ext.net button liseners work diffeerent from asp.net button,as it doesnt need render all page again.

sakir
  • 3,391
  • 8
  • 34
  • 50