如何提供一个“确认”对话框,然后激活服务器端代码

时间:2022-02-10 15:13:04

I have been given the task to re-code an old VB6 page. This page exports data from our database and imports it into another. While the export/import is happening, I need to offer the user confirm boxes. The context and results of these confirm boxes all depend on server-side validation. In the old code, the author simply did:

我被赋予了重新编码旧VB6页面的任务。此页面从我们的数据库导出数据并将其导入另一个数据库。在导出/导入过程中,我需要提供用户确认框。这些确认框的上下文和结果都取决于服务器端验证。在旧代码中,作者只是做了:

If MsgBox(Msg, vbOKCancel) = vbOK Then
                    GoTo Function1
                Else
                    GoTo Function2
                End If

Yes, those are GoTos, don't remind. This code is rough. Anyway, how in the heck can I do this in .NET with c# code behind?

是的,那些是GoTos,不要提醒。这段代码很粗糙。无论如何,我怎么能在.NET中用c#代码执行此操作?

1 个解决方案

#1


Well the code would be the same if it were C#, though it would look something like:

如果它是C#,代码将是相同的,尽管它看起来像:

if (Interaction.MsgBox(Msg, Constants.vbOKCancel) == Constants.vbOK) {
    goto Function1;
}
else {
    goto Function2;
}

But, if this is an ASP.NET application, it would look different. You'd probably make a modal dialog box and attach some click handlers to the buttons on that dialog.

但是,如果这是一个ASP.NET应用程序,它看起来会有所不同。您可能会创建一个模态对话框并将一些单击处理程序附加到该对话框上的按钮。

[edit] By the way, if you're ever in doubt about how VB code would look in C#, try a converter utility such as this one. They don't work all the time, but they work sometimes. Cheers.

[编辑]顺便说一句,如果您对VB代码在C#中的外观有所怀疑,请尝试使用转换器实用程序,例如此代码。它们不是一直都在工作,但它们有时会起作用。干杯。

#1


Well the code would be the same if it were C#, though it would look something like:

如果它是C#,代码将是相同的,尽管它看起来像:

if (Interaction.MsgBox(Msg, Constants.vbOKCancel) == Constants.vbOK) {
    goto Function1;
}
else {
    goto Function2;
}

But, if this is an ASP.NET application, it would look different. You'd probably make a modal dialog box and attach some click handlers to the buttons on that dialog.

但是,如果这是一个ASP.NET应用程序,它看起来会有所不同。您可能会创建一个模态对话框并将一些单击处理程序附加到该对话框上的按钮。

[edit] By the way, if you're ever in doubt about how VB code would look in C#, try a converter utility such as this one. They don't work all the time, but they work sometimes. Cheers.

[编辑]顺便说一句,如果您对VB代码在C#中的外观有所怀疑,请尝试使用转换器实用程序,例如此代码。它们不是一直都在工作,但它们有时会起作用。干杯。