Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to call server side Method using JavaScriptHow to call server side Method using JavaScript
Previous
 
Next
New Post
6/24/2010 11:13 AM
 


I want to know how I can execute "BindDataList" method (listed below) using a JavaScript function.

Any help will be appreciated.

Private Sub BindDataList()
            Try
 
                Dim objItemController As New ItemController
                Dim Items as System.Collections.IList = objItemController.ListItems(Me.ModuleId)
 
                dlSlides.DataSource = _photos
                dlSlides.DataBind()
 
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub
 
New Post
6/27/2010 8:38 PM
 
Use JavaScript to cause a post back:
<a href=" __doPostBack('BindDataList', '')">BindDataList</a>

Handle the post back in your Page_Load method:
protected void Page_Load(object sender, EventArgs e)
{
  var eventArgs = Request.Params.Get("__EVENTARGUMENT");//equals string.empty--the second argument to the __doPostBack method
  var eventTarget = Request.Params.Get("__EVENTTARGET");//equals "BindDataList"
 
  if (eventTarget == "BindDataList")
  {
    BindDataList();
  }
}
 
New Post
6/28/2010 3:05 AM
 
Hello, Thanks for your message.
 
New Post
6/28/2010 3:31 AM
 
Please go through the http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods  that will help you.

Regards
LeoTechnosoft Pvt.Ltd
 
New Post
6/28/2010 3:52 AM
 
Truly I was looking for a way to use callback method to avoid page post back.

I found a good sample of calling server side methods using 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...">
 
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
 function GetID()
{
 
var valueID = document.getElementById("txtID").value;
DoServerAction(valueID,'');
 
}
    function ReceiveDataFromServer(data)
    {
    document.getElementById("myNewData").innerHTML =data
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <input id="txtID" type="text" />
        <input type="button" value="Submit" onclick="GetID()" />
        <br />
        <div runat="server" id="myNewData"></div>
    </form>
</body>
</html>



Partial Class _Default
    Inherits System.Web.UI.Page
    Implements System.Web.UI.ICallbackEventHandler
    Protected ReturnData As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim CR_REF As String = ClientScript.GetCallbackEventReference(Me, "myValue", "ReceiveDataFromServer", "validateF")
 
        If Not ClientScript.IsClientScriptBlockRegistered("DoServerAction") Then
            Dim SERVER_SCRIPT As String = " function DoServerAction(myValue,validateF) { " + CR_REF + "}"
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "DoServerAction", SERVER_SCRIPT, True)
 
        End If
 
   
 
    End Sub
 
    Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
        Dim template As String = ""
        If ReturnData.ToLower = "name" Then
            template = "Morteza K"
        ElseIf ReturnData.ToLower = "address" Then
            template = "Never land"
        Else
            template = "Please Use Valid KeyWord--> Name , Address"
        End If
        Return template
    End Function
 
    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        If Not String.IsNullOrEmpty(eventArgument) Then
            ReturnData = eventArgument
        End If
    End Sub
End Class
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to call server side Method using JavaScriptHow to call server side Method using JavaScript


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out