Accessing WebMethod in UserControl via AJAX

Posted by Community Admin on 03-Aug-2018 13:57

Accessing WebMethod in UserControl via AJAX

All Replies

Posted by Community Admin on 24-Apr-2013 00:00

Hi,
I'm trying to do Newsletter Signup List. I want to add new e-mail address via ajax to my module but i cannot access to webmethod under my custom user control. Anyone can help me?

Ajax code:

$(function ()
       $('input[type=submit][id$=btnSubscribe]').click(function ()
           var Email = $('#<%=txtEmail.ClientID%>').val().trim();
 
           if (Email != "")
               $.ajax(
                   type: "POST",
                   url: "../../Widgets/ucNewsletterSignup.ascx/AddNewsletter",
                   data: "'Email': '" + Email + "'",
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (msg)
                       var array = msg.d;
 
                       alert("başarılı");
                   
               );
           
           else
 
           
 
           return false;
       );

and my WebMethod under ucNewsletterSignup.ascx User Control:

[WebMethod]
        public static void AddNewsletter(string Email)
        
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type newslettermoduleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.NewsletterModule.Newslettermodule");
            DynamicContent newslettermoduleItem = dynamicModuleManager.CreateDataItem(newslettermoduleType);
 
            newslettermoduleItem.SetValue("Email", Email);
 
            newslettermoduleItem.SetString("UrlName", "");
            newslettermoduleItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            newslettermoduleItem.SetValue("PublicationDate", DateTime.Now);
            newslettermoduleItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
 
            dynamicModuleManager.SaveChanges();
        

Posted by Community Admin on 24-Apr-2013 00:00

What does firebug tell you?...what's happening, can we see a screenshot of the expanded item in the console tab?

Easy (more elegant) fix is to just leverage the SF WCF framework, it's WAY easier than you think it is
http://www.sitefinitysteve.com/blog/code/2012/03/16/simple-wcf-by-sitefinity

Posted by Community Admin on 24-Apr-2013 00:00

Hi Steve,

Console returns me that error

Posted by Community Admin on 26-Apr-2013 00:00

Hi Cem,

The problem is most likely coming from some authorization issues, as the actual call is understood but not allowed. There are several articles which can help you on the topic:

forums.asp.net/.../1

stackoverflow.com/.../using-jquery-to-call-a-webmethod

All the best,
Victor Velev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed