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
Post a Comment