jquery - AJAX with ASP.NET: How to call a method of a user control using AJAX? -


i have master page has placeholder generate content default.aspx default.aspx defines user control:

<asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent">     <uc:maincontent id="maincontent" runat="server" /> </asp:content> 

user control has following code inside:

<div class="form-group">         <button type="button" class="btn btn-primary" text="get data" runat="server" data-toggle="model" data-target="#mymodal" title="provide year"             id="btngenerate" /> </div 

then, want call method, defined in user control code behind:

[system.web.services.webmethod] public static string generatepdfs() {     string test = "test string";     return test; } 

to have following jquery code:

$('#btngenerate').click(function () {      if (!validateinput()) {         return false;     }      $.ajax({         type: "post",         url: "????"         .....     }); 

i have created generic handler following code. found example on stackoverflow

public void processrequest (httpcontext context) {      using (var writer = new system.io.stringwriter())     {         page pageholder = new page();         var control = (usercontrol)pageholder.loadcontrol("~/controls/maincontent.ascx");         pageholder.controls.add(control);         context.server.execute(pageholder, writer, false);         context.response.contenttype = "text/html";         context.response.write(writer.getstringbuilder().tostring());     } } 

but example not explain how call web method defined in user control.

what right way accomplish that?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -