-2

I make a webmethod call and get an answer from the server if the current user can/can't print a document.

If the user can print, I want to display a print button. Otherwise not.

Is there a way to add a print button to an existing "div" from a web method?

Inbal
  • 909
  • 2
  • 28
  • 46
  • 1
    No, you can't add a button in the client DOM using a WebMethod but it can be done in client side script (same that called WebMethod) according to its response. – Adriano Repetti May 04 '14 at 09:16
  • please, add your code snippet to get better answer – ale May 04 '14 at 09:23
  • Thanks for your response. I don't want to do it from client-side for security reasons. The client can fake the server result and then get the print button although he is not allowed to print. – Inbal May 04 '14 at 10:05

2 Answers2

0

You should try something like this(sorry, not tested)

$.ajax({
  type: "POST",
  url: "/yourPage.aspx/YourWebMethod",
  data: "{yourParameterName:'" + yourparamvalue + "'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
      async: false,
  success: function (data) {
    var element = document.createElement("input");
    element.setAttribute("type", "button");
    element.setAttribute("value", "invert");
    element.setAttribute("name", "button3");
    element.setAttribute("onclick", "foo()");
    var targetElement = document.getElemanById('yourdivid');
    targetElement.appendChild(element);

  },
  error: function () { alert('/yourPage.aspx/YourWebMethod'); }
});
ale
  • 10,012
  • 5
  • 40
  • 49
  • Thanks for your response. I don't want to do it from client-side for security reasons. The client can fake the server result and then get the print button although he is not allowed to print. – Inbal May 04 '14 at 10:05
0

You dont need to add from web method, simply add button where ever you want to show, make sure it is hidden by default. check the value return from page method and show/hide button based on value.

PageMethods.CheckPermission(function (flag) {
    if (flag == "1")
        $("#btnPrint").show();
    else 
        $("#btnPrint").hide();
});
Rashmin Javiya
  • 5,173
  • 3
  • 27
  • 49