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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0jQuery + ajax + DNN ModulesjQuery + ajax + DNN Modules
Previous
 
Next
New Post
1/14/2014 6:18 PM
 

this is my complete code working very fine, ill be using this in the future a lot in my projects. this is basics in net programming imo so im posting it here. (damn editing posts here slows down firefox like hell. no code insert button?)

client side:

AutoPostBack="false"
onclick=<%# String.Format("onCheckedLevelClientClick(this, '{0}')", Eval("anQId"))%>
Checked='<%# (Eval("checkedLevel2").GetHashCode() = 1)%>' />

 function onCheckedLevelClientClick (checkbox, anQId)
       {
       sendAjaxRequest($(checkbox), { 'FUNCTION': 'saveOneCheckedCheckboxAjax', 'param0': anQId, 'param1': checkbox.checked });               
   }

   function sendAjaxRequest(htmlEl, jsonData) {
       jQuery.ajax({
           type: "POST",
           async: "false",
           url: location.href,
           dataType: "text",
           data: (jsonData),
           success: function (data) {
               dynNotifyEl(htmlEl, undefined, "Shranjeno", undefined);
           },
           error: function (XMLHttpRequest, textStatus, errorThrown) {
               dynNotifyEl(htmlEl, undefined, undefined, 'Napaka: ' + textStatus + ', ' + errorThrown);
           },
           beforeSend: function (xhr) {
               xhr.setRequestHeader("X-OFFICIAL-REQUEST-MINE", "TRUE");//Used to ID as a AJAX Request
               dynNotifyEl(htmlEl, "", undefined, undefined);
           },
           complete: function (XMLHttpRequest, textStatus) {
           }
       });
   }

            // create dynamic notification element
   // all arguments are optional except targetEl
   function dynNotifyEl(targetEl, waitMsg, saveMsg, errorMsg)
   {        
       var type = 0;
       var dynElExisting = targetEl.siblings(".notifyDiv");
       if (dynElExisting.length)
           dynElExisting.remove();        
       var dynEl;
       if (typeof errorMsg !== 'undefined') {
           type = 1;            
           dynEl = $('<div id="notifyDivErr" class="notifyDiv" style="background:#dd0000;position:absolute;display:none;color:white;">' + errorMsg + '</div>');
                    dynEl.bind("click", function () {
                        $(this).remove();
                    });
       }
       else if (typeof saveMsg !== 'undefined') {
           type = 2;
           dynEl = $('<div id="notifyDivSucc" class="notifyDiv" style="background:#98bf21;position:absolute;display:none;color:white;">' + saveMsg + '</div>');
       }
       else if (typeof waitMsg !== 'undefined') {
           type = 3;
           dynEl = $('<div id="notifyDivWait" class="notifyDiv" style="position:absolute;display:none;"><img src="/desktopmodules/elura/images/ajax-loader.gif" />' + waitMsg + ' </div>');
       }
       if (type != 0) {
           targetEl.after(dynEl);
           var targetPos = targetEl.position();
           dynEl.css({
               'top': targetPos.top + targetEl.height(),
               'left': targetPos.left + targetEl.width() + 5
           }).fadeIn('slow');
           if (type == 2) {
               dynEl.fadeOut('slow', function(){
                   $(this).remove();
               });
           }
       }
   }

server side:

If Request.Headers("X-OFFICIAL-REQUEST-MINE") = "TRUE" Then
                AjaxWrapper()
            End If

Protected Sub AjaxWrapper()
        Response.Clear()
        Dim strData As String = ""
        Try
            Dim mi As MethodInfo = [GetType]().GetMethod(Request.Params("FUNCTION"), BindingFlags.Instance Or BindingFlags.NonPublic)
            Dim objs As Object() = New Object(mi.GetParameters().Length - 1) {}
            For i As Integer = 0 To objs.Length - 1
                objs(i) = (New PortalSecurity()).InputFilter(Request.Params("param" + CStr(i)), PortalSecurity.FilterFlag.NoMarkup)
            Next
            strData = mi.Invoke(Me, objs).ToString()
        Catch ex As Exception
            strData = "{Error : Caught}"
            Exceptions.ProcessModuleLoadException(Me, ex)
        End Try
        Response.Write(strData)
        Response.Flush()
        Try
            Response.Close()
        Catch
        End Try
        'It likes to break sometimes - and other times it's needed
        Response.[End]()
        Return
    End Sub

Protected Function saveOneCheckedCheckboxAjax(anQIdStr As String, checkedStr As String) As String
        saveOneCheckedCheckbox(Convert.ToInt32(anQIdStr), "checkedLevel2", Convert.ToBoolean(checkedStr))        
        Response.ContentType = "text"
        Return "1"
    End Function
 
New Post
2/13/2017 5:50 AM
 
hi , thank you . it helped me so much .
it's bad not to have page entries but i handled it .
I have a question , how can I use returned data ? please help .
 
New Post
2/13/2017 6:06 AM
 
Hi , thank you for your help . it worked for me .
I have a question , how can I use returned value ?
 
New Post
2/13/2017 6:08 AM
 
Hi , thank you for your help .


I have a question , how can I use returned value ? please help .
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0jQuery + ajax + DNN ModulesjQuery + ajax + DNN Modules


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