当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Using JQuery Modal Diaglog to fire a Server Side Control

问题描述:

OK so I have a jquery modal dialog. It accepts an input and then has an ok and and cancel button. Cancel works fine by simply closing the dialog. The ok button fires the OnClientClick when I really want it to fire the OnClick method so I can go into the server controls and log the input into the database using ASP.NET. Any ideas on how this is supposed to be done using jquery?

Side note: I'm not currently by the computer that has the code, but I'll try to update it as soon as I can.

网友答案:

You could try this:

Insert a ASP.NET button on your form, binded to the event that you want to trigger, then, with jQuery do $('#your_button_ID').click(); on the 'OK' event of your dialog.

Hope it helps!

网友答案:

In your codebehind create a static function and add the [WebMethod] attribute, so now you can fire code behind methods from Jquery.

javascript:__doPostBack('IDOfYourControlButton','')

This is the same method a button or linkbutton uses to fire the onClick event in .NET

Demo webmethod in code behind you add this

[System.Web.Services.WebMethod]
public static string SayHi()
{
    return "Hi";
}

in yr aspx file you add this javascript

<script>
        function GetHi() {

            PageMethods.SayHi(onComplete);
        }

        function onComplete(result) {
            alert(result);
        }

        GetHi();
</script>

and dont forget to add this also in yr site.master or aspx page right under the

    <form runat="server">
    <asp:ScriptManager ID="scriptManager" EnablePageMethods="true" runat="server"/>
</form>
分享给朋友:
您可能感兴趣的文章:
随机阅读: