简体   繁体   English

从window.confirm检索值,位于代码后面。 [VB.net]

[英]Retrieve value from window.confirm, in code-behind. [VB.net]

I am doing a project where I have made a button that adds a product. 我正在做一个项目,在其中创建了一个添加产品的按钮。

When the user clicks this it calls a function that adds the product, and then looks through my DataBase(CheckProdRef function), to see if this product has some "followup" products. 当用户单击此按钮时,它将调用一个添加产品的函数,然后浏览我的数据库(CheckProdRef函数),以查看该产品是否具有某些“后续产品”。

If this is the case, I want my sub to make a pop-up box, "This product has a follow-up product, do you wish to add?". 如果是这种情况,我希望我的订阅者在弹出框中显示“此产品有后续产品,您想添加吗?”。

Then based on the answer from the user, I should add the product, or not. 然后,根据用户的回答,我应该添加产品还是不添加产品。

However I have the dear problem that I cannot really seem to retrieve any meaningful value from the window.confirm . 但是我有一个亲爱的问题,我似乎无法真正从window.confirm中检索任何有意义的值。

My code is this: 我的代码是这样的:

Protected Sub BTN_EM_TILFØJ_Click(sender As Object, e As EventArgs) Handles BTN_EM_TILFØJ.Click
    Dim Lbl As New System.Web.UI.WebControls.Label

    Call AddRowTbl(GV_EM, "MAT")

    If CheckProdRef(TB_PROD_NR.Text) <> vbNullString Then

        Lbl.Text = "<script language='javascript'>" & Environment.NewLine _
& "window.confirm(" & "'" & "There is a followup product, do you wish to add it?" & "'" & ")</script>"
        Page.Controls.Add(Lbl)

The following is my desperate check to see if true/false was the value, which it is not 以下是我不顾一切的检查,看是否是true / false值,不是

If Lbl.Text = "True" Then`  
    Labtest.Text = "Du trykkede ok"
Else
    Labtest.Text = "du trykkede cancel"
End If

and then it goes onxxxxxxxxxxxxx

I need a way to register if the user clicks yes or no. 如果用户单击“是”或“否”,我需要一种注册方法。 And I dont see how I can add the functionality to the button, as this pop-up only is shown IF there is a follow-up product(obv). 我不知道怎样才能将功能添加到按钮,只显示如果有后续产品(OBV)此弹出。

Assuming you are using ajaxcontroltoolkit, you can do this: 假设您正在使用ajaxcontroltoolkit,则可以执行以下操作:

On your aspx add a block of code refering to the "popup" which will be showing the message to the user 在您的aspx上添加引用“ popup”的代码块,该代码块将向用户显示消息

<AjaxToolKit:ModalPopupExtender ID="mpeDiscrepancias" <-- ID to be used on code behind runat="server" TargetControlID="NuevaDiscrepanciaBtn" <-- button that will be popping out the message
            PopupControlID="DiscrepanciaPanel" <-- control that will be displayed BackgroundCssClass="modalBackground" <-- css class for the modal CancelControlID="CerrarDiscrepanciaBtn"<-- button that will be closing the modal
            Enabled="True">
        </AjaxToolKit:ModalPopupExtender>

        <div id="DiscrepanciaPanel" style="background-color: gray; display: none; max-height: 600px; overflow: auto;max-width:95%">

            <table style="text-align:left">
                <tr>
                    <td colspan="2" class="MainTitle">
                        YOUR MESSAGE
                    </td>
                </tr>
                <tr>
                    <td>

                    </td>
                    <td>

                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <br />
                        <asp:Button ID="GuardarDiscrepanciaBtn" <-- save button runat="server" Text="Guardar" CausesValidation="true" ValidationGroup="Discrepancias" OnClick="GuardarDiscrepanciaBtn_Click" <--on click action />
                        <asp:Button ID="CerrarDiscrepanciaBtn"<-- close modal button runat="server" Text="Cerrar" CausesValidation="False" />
                    </td>
                </tr>
            </table>
        </div>

As you can see is pretty easy, just remember that TargetControlID, popupControlID and CancelControlID they need to exist, in order to work, if you are showing the modal by an action, just add a dummy to be the targetControlId, i use a hiddenfield 如您所见,这很简单,只需记住它们需要存在的TargetControlID,popupControlID和CancelControlID,才能正常工作,如果要通过操作显示模态,只需添加一个虚拟对象作为targetControlId,我就使用了hiddenfield

<asp:HiddenField ID="NuevaDiscrepanciaBtn" runat="server" />

then on your code behind is pretty simple as this. 然后在您的代码后面就很简单了

if(conditions that makes your item has more items)
 YourPopUpExtenderId.show()

then you can handle the save button as a regular button. 那么您可以将保存按钮作为常规按钮进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM