Results 1 to 2 of 2
  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    South Africa

    Calling a Shared function from the Client side

    Good Day

    i have a shared function as called in vb.net or static function in C# that is declared like this

        'Run JQuery using this 
        Public Shared Function runjQueryCode(ByVal jsCodetoRun As String, ByVal Page As Page)
            Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Page)
            If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then
                ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True)
                Page.ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True)
            End If
        End Function
    now the function is running the jquery from the server side, this works well now i want to call this function from the client side inside a nested table in a listview like this

    <div id="Div2" runat="server"  %>'  
     <a href="#" onclick=' <%# clsFunctions.runjQueryCode("$('#basic-modal-ontent').modal()", this)  %>'></a>
    <img src="../../Imgs/Linkquestionare.png" border="0"/></a></div>
    Now i have two Questions. the first one is my function accept the JQuery string and the reference to the page. Well i can do this on the server side and i am able to do this nicely , but i want to do it on the client side

    The following is content that i want to pass to the function as the first argument. /


    and as you can see, i tried to pass "this" trying to get the reference to the page.

    1) in would like to pass that string in the function as my first argument
    2) i want to pass the page reference to the function as my second parameter.


  2. #2
    Fanatic Member
    Join Date
    Feb 2000

    Re: Calling a Shared function from the Client side

    in the second parameter 'this' in JQuery is an Object. On the server you have declared it as Page. You might need to change the server side code to accept Object.

    I also believe that you might have to decorate the serverside method with

    Public Shared........
    Change your onclick event to call a JQuery function in the form....

    $("#id").click(function (event) {
                url: rootDir + Page/Method',
                type: 'POST',
                dataType: 'json',
                data: { jsCodetoRun : "$('#basic-modal-ontent').modal()", Page: this }
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                error: function (data, textStatus, exceptionThrown) {

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width