简体   繁体   English

在vb.net中获取确认值

[英]Get Confirm value in vb.net

I have a hidden asp Button in a Repeater. 我在中继器中有一个隐藏的asp按钮。 In the VB.NET code behind I use the Rerpeater_ItemCommand to get the click event within the Repeater. 在后面的VB.NET代码中,我使用Rerpeater_ItemCommand来获取Repeater中的click事件。 There's a check if user is already recording a project. 检查用户是否已经在录制项目。 If yes and he wants to start a new one, a confirm box should appear asking "Are you sure?" 如果是,并且他想开始一个新的,则出现一个确认框,询问“您确定吗?” How can I access the click value from confirm? 如何从确认中访问点击值?

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
        <ItemTemplate>

        <div class="tile user_view user_<%# Eval("employeeName") %>">
        <div class="tilesheight"></div>
        <div class="element">

        <asp:Button ID="Button1" CssClass="hiddenbutton" runat="server" /> 


            Index: 
            <asp:Label ID="Label1" runat="server"
                Text='<%# Eval("index") %>' /><br />
            <hr class="hr" />

            customer:
            <asp:Label ID="CustomerLabel" runat="server" 
                Text='<%# Eval("customer") %>' /><br />
            <hr class ="hr" />
            order:
            <asp:Label ID="OrderNoLabel" runat="server" 
                Text='<%# Eval("orderNo") %>' /><br />
            <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%# Eval("description") %>' /><br />
            <hr class="hr" />

        </div>
        </div>
        </ItemTemplate>
        </asp:Repeater>

code behind: 后面的代码:

If empRecs.Contains(projects.Item(index.Text).employeeID) Then

            'Catch index of recording order
            i = empRecs.IndexOf(projects.Item(index.Text).employeeID)


                Page.ClientScript.RegisterStartupScript(Me.GetType, "confirm", "confirm('Order " & empRecs(i + 2) & " already recording. Would you like to start a new one?')",True)

                'If users clicks ok insertData()

        End If

Other solutions are using the Click Event and a hidden field. 其他解决方案使用Click事件和一个隐藏字段。 But the problem is, I don't want the confirmbox to appear every time the button is clicked. 但是问题是,我不希望每次单击按钮时都显示确认框。 Only when empRecs conatins an employee. 仅当empRecs使雇员成为员工时。

Thanks for helping 感谢您的帮助

you could try putting the following 您可以尝试将以下内容

Proteted Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
 If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    ''not sure where you get the empRecs and projects from 
    ''but you can get the data item bound to this iteration of the repeater thus
    ''if you need it for the empRecs/projects bit
    Dim data = DirectCast(e.Item.DataItem, TypeOfBoundData)
    ''grab the button like this
    dim but as Button = e.Item.FindControl("Button1") ''cant remember if that will work, if not try the next line
    ''dim but = DirectCast(e.Item.Findcontrol("Button1"), Button)
    ''then do your bit
    If empRecs.Contains(projects.Item(index.Text).employeeID) Then
        AddHandler but.Click, AddressOf Button1_Click
        but.OnClientClick = "return confirm('Order " & empRecs(i + 2) & " already recording. Would you like to start a new one?')"
    End If
  End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   insertData()
End Sub

hth 心连心

Not sure if I got your question right, but I got that you want to be able to tell when the "Yes" option from the confirm dialog has been selected. 不知道我是否正确回答了您的问题,但是我想知道您是否能够确定何时从确认对话框中选择了“是”选项。 You can do that by adding the following directly on the markup rather than the code-behind: 您可以通过以下方式直接在标记上添加代码,而不是在代码后面添加代码:

<asp:Button ID="Button1" CssClass="hiddenbutton" runat="server" OnClientClick="javascript:if(!confirm('Your confirm text here')) {return false;} />

Whatever event is triggered by that button, won't fire up until the user has confirmed the dialog. 无论该按钮触发了什么事件,在用户确认对话框之前都不会触发。

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

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