Reputation: 29
I have a hidden asp Button in a Repeater. In the VB.NET code behind I use the Rerpeater_ItemCommand to get the click event within the Repeater. 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. But the problem is, I don't want the confirmbox to appear every time the button is clicked. Only when empRecs conatins an employee.
Thanks for helping
Upvotes: 2
Views: 2009
Reputation: 167
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.
Upvotes: 0
Reputation: 2197
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
Upvotes: 1