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

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Error post data using ajax within a dnn moduleError post data using ajax within a dnn module
Previous
 
Next
New Post
3/9/2012 11:28 AM
 

Hello,

I'm trying to post data and return it back to my page using ajax and jquery. Don't seem to know what i'm doing wrong.  Please help..

Below is what I have done. 

Markup

<script type="text/javascript">
    $(document).ready(function() {
        $('#<%= PracticeButton.ClientID %>').click(BindTextbox);
    });


    function BindTextbox() {
        $.ajax({
            type: "POST",
            url: '/dotnetnuke5/DesktopModules/GlobalPay.MainBoard/ViewMainBoard.ascx/GetDetails',
            data: "{}",
            contentType: "application/json",
            dataType: "json",
            success: function(data) {
                for (var i = 0; i < data.d.length; i++) {
                    $("#table1").append("<tr><td>" + data.d[i].FirstName + "</td><td>" + data.d[i].Age + "</td></tr>");
                }
                //                $('#<%= PractiseTextbox.ClientID %>').val(data);
//                 data.d.GetDetails);
            }
        })
    }
</script>

<div>

<asp:TextBox runat="server" ID="PractiseTextbox"></asp:TextBox>
    <asp:Button runat="server" ID="PracticeButton" Text="Test" />
    <table style="width: 100%;" id="table1">       
    </table>

</div

Code Behind

protected void Page_Load(object sender, EventArgs e)
        {
            DotNetNuke.Framework.jQuery.RequestRegistration();
            //register the accordion script
            if (!DotNetNuke.UI.Utilities.ClientAPI.IsClientScriptBlockRegistered(Page, "ui.core.js"))
            {
                DotNetNuke.UI.Utilities.ClientAPI.RegisterClientScriptBlock(Page, 
                    "ui.core.js", "<script src=\"" + Request.ApplicationPath +
                    "/jquery-1.4.1.min.js\" type=\"text/javascript\"></script>");
            }

  [WebMethod]
        public static Names[] GetNames()
        {
            List<Names> list = new List<Names>();
            DataTable dt = DataStore.GetDataTable();
            foreach (DataRow row in dt.Rows)
            {
                Names _names = new Names();
                _names.FirstName = row["Name"].ToString();
                _names.Age = row["age"].ToString();
                list.Add(_names);
            }
            return list.ToArray();
        }


    }
    public class DataStore
    {
         public static DataTable GetDataTable()
        {
            DataTable dt = new DataTable("Names");
            DataColumn dc1 = new DataColumn("Name");
            DataColumn dc2 = new DataColumn("Age");
            dt.Columns.AddRange(new DataColumn[] { dc1, dc2 });
            DataRow dr1 = dt.NewRow();
            dr1[0] = "Ahmed";
            dr1[1] = "27";
            DataRow dr2 = dt.NewRow();
            dr2[0] = "Peter";
            dr2[1] = "30";
            DataRow dr3 = dt.NewRow();
            dr3[0] = "John";
            dr3[1] = "20";
            DataRow dr4 = dt.NewRow();
            dr4[0] = "Ali";
            dr4[1] = "30";
            dt.Rows.Add(dr1);
            dt.Rows.Add(dr2);
            dt.Rows.Add(dr3);
            dt.Rows.Add(dr4);
            return dt;
         }
    }


    public class Names
    {
        private string _firstName;
        private string _age;
        public string FirstName
        {
            set { _firstName = value; }
            get { return _firstName; }
        }
        public string Age
        {
            set { _age = value; }
            get { return _age; }
        }
    }
        }




 
New Post
3/9/2012 10:59 PM
 
You can not send post to .ascx control. It should be .aspx page with this control.
 
New Post
3/10/2012 4:46 AM
 

Sir,

Could you illustrate what you have just said perhaps using my work. Because I don't seem to understand what you just said.

 
New Post
3/10/2012 11:35 AM
 

John

This control uses by DNN module (probably it has name GlobalPay.MainBoard). You should add this module to the DNN page (this page has own URL). You should send POST from your AJAX query to this URL instead of .ascx.

Sergey

 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Error post data using ajax within a dnn moduleError post data using ajax within a dnn module


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