开发者

How to fire C# code from JavaScript (ModalPopupExtender/ajaxToolkit)

I am using ASP.NET/C# Framework 3.5/SQL Server 开发者_如何学编程with AjaxControlToolkit's ModalPopupExtender to freeze the main window.

The use-case is that when a user clicks the Break Button, the screen have to be frozen, which I am able to do so by using ModalPopupExtender. But then in the ModalPopupExtender I have given two buttons as follows:-

<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" 
    DropShadow="true"
    X="500"
    Y="100"
    BackgroundCssClass="modalBackground"
    OkControlID="btnBack"
    OnOkScript="BackButton_Click()"
    CancelControlID="btnCancel"
    OnCancelScript="CancelButton_Click()"
    PopupControlID="Panel1"
    PopupDragHandleControlID="Panel3"
    TargetControlID="lbn_job_det">
</ajaxToolkit:ModalPopupExtender>

In the PopupWindow I have two buttons,

  1. Back from Break and
  2. Cancel.

While on clicking of Back button, I need to do insertion in DB.

I searched a lot for the workarounds, but found nothing, some blogs said to create an Ajax-based website, and some used to say create a Web Service.

The C# Code is as follows:-

public string BackFromBreak(string argument)
{
    lblStatus.Text = "Redirected from BackFromBreak";
    if (argument == "back")
    {
        return "endbreak";
    } 
    else
    {
        return "";
    }
}


You can't call c# code directly from javascript in a Web app simply because they run in two different places, server side and client side respectively. So you have to decide. If you want to call some server side logic from javascript(i.e. ajax) or do a complete postback to execute de c# code. Best regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜