CyberUnDead
asked on
ASP.NET Nested Repeater Button Event
Using information garnered from the Exchange in particular:
https://www.experts-exchange.com/questions/20697348/ASP-NET-Bound-Repeater-in-Conditional-Table-Formatting.html
https://www.experts-exchange.com/questions/21185725/Repeater-Command-Not-being-executed.html
I have a nested repeater "Child1Repeater" inside of "ParentRepeater" that has "btnReg" as a button. Also the ParentRepeater has a literal of "litActivityID" which contains an integer value say "122"
Whenever the user clicks on btnReg the following method executes:
Protected Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
HttpContext.Current.Respon se.Redirec t("Registe rActivity. aspx?activ ityid=")
End Sub
My question is what is the best way pass the litActivityID.text to my a different webpage (RegisterActivity.aspx). I was thinking through the URI but how do I add the litActivityID.text to pass?
https://www.experts-exchange.com/questions/20697348/ASP-NET-Bound-Repeater-in-Conditional-Table-Formatting.html
https://www.experts-exchange.com/questions/21185725/Repeater-Command-Not-being-executed.html
I have a nested repeater "Child1Repeater" inside of "ParentRepeater" that has "btnReg" as a button. Also the ParentRepeater has a literal of "litActivityID" which contains an integer value say "122"
Whenever the user clicks on btnReg the following method executes:
Protected Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
HttpContext.Current.Respon
End Sub
My question is what is the best way pass the litActivityID.text to my a different webpage (RegisterActivity.aspx). I was thinking through the URI but how do I add the litActivityID.text to pass?
ASKER
-Thespian-:
How do I assign an ID in the markup? My current button under the Child1Repeater looks like:
<asp:Button ID="btnReg" runat="Server" Text="Register" OnClick="btnReg_Click" Visible="false" />
The ID is in the ParentRepeater and it looks like:
<asp:Literal ID="litActivityID" runat="Server" Text='<%#Container.DataIte m("Activit y_ID")%>' Visible="true" />
Once assigned how will I find the correct button in my ParentRepeater_ItemDataBou nd subroutine which has the code
Dim btnReg As Button = rptChild.Items(0).FindCont rol("btnRe g")
I am using ItemDataBound because depending upon the field value the button will be visible or not. (i.e. You can't register for an activity you already part of).
How do I assign an ID in the markup? My current button under the Child1Repeater looks like:
<asp:Button ID="btnReg" runat="Server" Text="Register" OnClick="btnReg_Click" Visible="false" />
The ID is in the ParentRepeater and it looks like:
<asp:Literal ID="litActivityID" runat="Server" Text='<%#Container.DataIte
Once assigned how will I find the correct button in my ParentRepeater_ItemDataBou
Dim btnReg As Button = rptChild.Items(0).FindCont
I am using ItemDataBound because depending upon the field value the button will be visible or not. (i.e. You can't register for an activity you already part of).
hm... can u provide the interface code of the repeater?
ASKER
-Thespian-:
Here is an abbreviated version but includes all the necessary parts for my question.
<asp:Repeater id="ParentRepeater" runat="server">
<HeaderTemplate>
<table style="width: 100%;">
</HeaderTemplate>
<SeparatorTemplate>
<tr>
<td colspan="6"> </td>
</tr>
</SeparatorTemplate>
<ItemTemplate>
<tr>
<td style="border-bottom: 2px solid black;" colspan="6">
<asp:Literal ID="litDate" runat="Server" Text='<%#CheckDate(Contain er.DataIte m("date")) %>' />
</td>
<ul>
</tr>
<asp:Repeater id="Child1Repeater" runat="server" datasource='<%# Container.DataItem.Row.Get ChildRows( "date") %>'>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width: 20px">
<li/><asp:Literal ID="litActivityID" runat="Server" Text='<%#Container.DataIte m("Activit y_ID")%>' Visible="true" />
</td>
<td style="width: 200px;">
<i><asp:Literal ID="litActivity" runat="Server" Text='<%#Container.DataIte m("Activit y_Title")% >' /></i>
</td>
<td style="width: 60px; text-align: center;">
<asp:Literal ID="litStatus" runat="Server" Text='<%#CheckStatus(Conta iner.DataI tem("Statu s"))%>' />
<asp:Button ID="btnReg" runat="Server" Text="Register" OnClick="btnReg_Click" Visible="false" />
</td>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
<FooterTemplate>
</ul>
</tr>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Here is an abbreviated version but includes all the necessary parts for my question.
<asp:Repeater id="ParentRepeater" runat="server">
<HeaderTemplate>
<table style="width: 100%;">
</HeaderTemplate>
<SeparatorTemplate>
<tr>
<td colspan="6"> </td>
</tr>
</SeparatorTemplate>
<ItemTemplate>
<tr>
<td style="border-bottom: 2px solid black;" colspan="6">
<asp:Literal ID="litDate" runat="Server" Text='<%#CheckDate(Contain
</td>
<ul>
</tr>
<asp:Repeater id="Child1Repeater" runat="server" datasource='<%# Container.DataItem.Row.Get
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width: 20px">
<li/><asp:Literal ID="litActivityID" runat="Server" Text='<%#Container.DataIte
</td>
<td style="width: 200px;">
<i><asp:Literal ID="litActivity" runat="Server" Text='<%#Container.DataIte
</td>
<td style="width: 60px; text-align: center;">
<asp:Literal ID="litStatus" runat="Server" Text='<%#CheckStatus(Conta
<asp:Button ID="btnReg" runat="Server" Text="Register" OnClick="btnReg_Click" Visible="false" />
</td>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
<FooterTemplate>
</ul>
</tr>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
-Thespian-:
That adds the activityid to the button's id. However how can pick the correct button out from
ParentRepeater_ItemDataBou nd subroutine
'Dim btnReg As Button = rptChild.Items(0).FindCont rol("btnRe g")
'btnReg.Visible = True
That adds the activityid to the button's id. However how can pick the correct button out from
ParentRepeater_ItemDataBou
'Dim btnReg As Button = rptChild.Items(0).FindCont
'btnReg.Visible = True
ASKER
Thanks for you patience -Thespian-:
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
-Thespian-:
I have substituted your code in all the necessary places. After the code to find my new button with the appropriate activityid I check a condition.
If the "Status" equals "Available" I want to change the button visibility to true from the default false.
So I use the code
btnReg.visible = true
However I receive an error doing this.
Object reference not set to an instance of an object.
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
I have broken up your code and to display the output and I know I am good right up to findcontrol. This is my ParentRepeater_ItemDataBou nd method:
Protected Sub ParentRepeater_ItemDataBou nd(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. RepeaterIt emActivity Args) Handles ParentRepeater.ItemDataBou nd
If ((e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingIt em)) Then
Dim rptChild As Repeater = CType(e.Item.FindControl(" Child1Repe ater"), Repeater)
Dim litStatus As Literal = CType(rptChild.Items(0).Fi ndControl( "litStatus "), Literal)
Dim strActivityID As Literal = CType(rptChild.Items(0).Fi ndControl( "litActivi tyID"), Literal)
If (litStatus.Text = "Available") Then
Dim strButton As String = "btnReg_" & strActivityID.Text
Dim btnReg As Button = btnReg = rptChild.Items(0).FindCont rol(strBut ton)
MsgBox(strButton)
btnReg.Visible = True
litStatus.Visible = False
End If
End If
End Sub
I have substituted your code in all the necessary places. After the code to find my new button with the appropriate activityid I check a condition.
If the "Status" equals "Available" I want to change the button visibility to true from the default false.
So I use the code
btnReg.visible = true
However I receive an error doing this.
Object reference not set to an instance of an object.
System.NullReferenceExcept
I have broken up your code and to display the output and I know I am good right up to findcontrol. This is my ParentRepeater_ItemDataBou
Protected Sub ParentRepeater_ItemDataBou
If ((e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingIt
Dim rptChild As Repeater = CType(e.Item.FindControl("
Dim litStatus As Literal = CType(rptChild.Items(0).Fi
Dim strActivityID As Literal = CType(rptChild.Items(0).Fi
If (litStatus.Text = "Available") Then
Dim strButton As String = "btnReg_" & strActivityID.Text
Dim btnReg As Button = btnReg = rptChild.Items(0).FindCont
MsgBox(strButton)
btnReg.Visible = True
litStatus.Visible = False
End If
End If
End Sub
ASKER
Opps the line that reads
Dim btnReg As Button = btnReg = rptChild.Items(0).FindCont rol(strBut ton)
should be:
Dim btnReg = rptChild.Items(0).FindCont rol(strBut ton)
Dim btnReg As Button = btnReg = rptChild.Items(0).FindCont
should be:
Dim btnReg = rptChild.Items(0).FindCont
ASKER
I am also increasing the point value to 500.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Than in OnClick procedure you will get an ID:
CType(sender, Button).ID.Substring(4)
And pass it as parameter. ;)