如何从JavaScript中激活C#代码(ModalPopupExtender / ajaxToolkit)

时间:2022-04-12 15:46:09

I am using ASP.NET/C# Framework 3.5/SQL Server with AjaxControlToolkit's ModalPopupExtender to freeze the main window.

我使用ASP.NET / C#Framework 3.5 / SQL Server和AjaxControlToolkit的ModalPopupExtender来冻结主窗口。

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:-

用例是当用户点击Break Button时,必须冻结屏幕,我可以使用ModalPopupExtender这样做。但是在ModalPopupExtender中我给出了两个按钮如下: -

<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,

在PopupWindow我有两个按钮,

  1. Back from Break and
  2. 从休息和回来
  3. Cancel.
  4. 取消。

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.

我搜索了大量的解决方法,但没有发现任何东西,一些博客说创建一个基于Ajax的网站,有些人曾经说过创建一个Web服务。

The C# Code is as follows:-

C#代码如下: -

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

1 个解决方案

#1


1  

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

您不能直接从Web应用程序中的javascript调用c#代码,因为它们分别在服务器端和客户端两个不同的位置运行。所以你必须做出决定。如果你想从javascript(即ajax)调用一些服务器端逻辑,或者做一个完整的回发来执行de c#代码。最好的祝福

#1


1  

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

您不能直接从Web应用程序中的javascript调用c#代码,因为它们分别在服务器端和客户端两个不同的位置运行。所以你必须做出决定。如果你想从javascript(即ajax)调用一些服务器端逻辑,或者做一个完整的回发来执行de c#代码。最好的祝福