Put value from DataList on user control to parent page?  
Author Message
Cousinzeke





PostPosted: Thu Oct 30 16:01:19 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? I have a user control (menu) with a data list:

<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:hyperlink
cssclass="MenuSelected"
id="myLink2"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>

I want to take the value of the Text attribute (the data item:
"Subject") from the selected item and put it in a label on the parent
page. I have spent a day and a half trying this, so I decided to ask
if anyone out there can help me. Thanks!

Web Programming107  
 
 
John





PostPosted: Thu Oct 30 16:01:19 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> I have a user control (menu) with a data list:
>
> <asp:DataList id="MyList" runat="server">
> <ItemTemplate>
> <asp:hyperlink
> cssclass="MenuUnselected"
> id="myLink1"
> Text='<%# Container.DataItem("Subject") %>'
> NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> %>'
> runat="server" />
> </ItemTemplate>
> <SelectedItemTemplate>
> <asp:hyperlink
> cssclass="MenuSelected"
> id="myLink2"
> Text='<%# Container.DataItem("Subject") %>'
> NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> %>'
> runat="server" />
> </SelectedItemTemplate>
> </asp:DataList>
>
> I want to take the value of the Text attribute (the data item:
> "Subject") from the selected item and put it in a label on the parent
> page. I have spent a day and a half trying this, so I decided to ask
> if anyone out there can help me. Thanks!

With ASP.NET, it's best to think a bit object-oriented.

So, why should your user control know anything about the page it happens to
be loaded into? In particular, why should it know that there's a label on
that page? Answer: it shouldn't.

On the other hand, the user control does know about the Text attribute of
the selected item. You could define a public property in the user control
which would expose that Text attribute so that any containing page (or other
control) can see the value of the Text attribute.

If the surrounding page needs to know when the selected index has changed
(so that it knows to fetch the Text property) then you can define a public
event in your user control and raise it when the user control receives the
SelectedIndexChanged event.
--
John


 
 
mkerrigan





PostPosted: Thu Oct 30 19:57:19 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? OK - I know how to assign a value to the public property, but what I
can't figure out is the syntax to retrieve the Text attribute's value
for the selected item. ???

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<OfK$EMail@HideDomain.com>...
> "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > I have a user control (menu) with a data list:
> >
> > <asp:DataList id="MyList" runat="server">
> > <ItemTemplate>
> > <asp:hyperlink
> > cssclass="MenuUnselected"
> > id="myLink1"
> > Text='<%# Container.DataItem("Subject") %>'
> > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> > %>'
> > runat="server" />
> > </ItemTemplate>
> > <SelectedItemTemplate>
> > <asp:hyperlink
> > cssclass="MenuSelected"
> > id="myLink2"
> > Text='<%# Container.DataItem("Subject") %>'
> > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> > %>'
> > runat="server" />
> > </SelectedItemTemplate>
> > </asp:DataList>
> >
> > I want to take the value of the Text attribute (the data item:
> > "Subject") from the selected item and put it in a label on the parent
> > page. I have spent a day and a half trying this, so I decided to ask
> > if anyone out there can help me. Thanks!
>
> With ASP.NET, it's best to think a bit object-oriented.
>
> So, why should your user control know anything about the page it happens to
> be loaded into? In particular, why should it know that there's a label on
> that page? Answer: it shouldn't.
>
> On the other hand, the user control does know about the Text attribute of
> the selected item. You could define a public property in the user control
> which would expose that Text attribute so that any containing page (or other
> control) can see the value of the Text attribute.
>
> If the surrounding page needs to know when the selected index has changed
> (so that it knows to fetch the Text property) then you can define a public
> event in your user control and raise it when the user control receives the
> SelectedIndexChanged event.
 
 
mkerrigan





PostPosted: Fri Oct 31 12:25:22 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? Here's one thing I have tried which didn't work:

Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyList.SelectedIndexChanged

Dim myListItem As DataListItem = CType(sender,
DataList).SelectedItem
Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
Dim myValue As String = myHyperlink.Text
lblTest.Text = myValue

End Sub




EMail@HideDomain.com (Mary Kerrigan) wrote in message news:<EMail@HideDomain.com>...
> OK - I know how to assign a value to the public property, but what I
> can't figure out is the syntax to retrieve the Text attribute's value
> for the selected item. ???
>
> "John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<OfK$EMail@HideDomain.com>...
> > "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> > > I have a user control (menu) with a data list:
> > >
> > > <asp:DataList id="MyList" runat="server">
> > > <ItemTemplate>
> > > <asp:hyperlink
> > > cssclass="MenuUnselected"
> > > id="myLink1"
> > > Text='<%# Container.DataItem("Subject") %>'
> > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> > > %>'
> > > runat="server" />
> > > </ItemTemplate>
> > > <SelectedItemTemplate>
> > > <asp:hyperlink
> > > cssclass="MenuSelected"
> > > id="myLink2"
> > > Text='<%# Container.DataItem("Subject") %>'
> > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
> > > %>'
> > > runat="server" />
> > > </SelectedItemTemplate>
> > > </asp:DataList>
> > >
> > > I want to take the value of the Text attribute (the data item:
> > > "Subject") from the selected item and put it in a label on the parent
> > > page. I have spent a day and a half trying this, so I decided to ask
> > > if anyone out there can help me. Thanks!
> >
> > With ASP.NET, it's best to think a bit object-oriented.
> >
> > So, why should your user control know anything about the page it happens to
> > be loaded into? In particular, why should it know that there's a label on
> > that page? Answer: it shouldn't.
> >
> > On the other hand, the user control does know about the Text attribute of
> > the selected item. You could define a public property in the user control
> > which would expose that Text attribute so that any containing page (or other
> > control) can see the value of the Text attribute.
> >
> > If the surrounding page needs to know when the selected index has changed
> > (so that it knows to fetch the Text property) then you can define a public
> > event in your user control and raise it when the user control receives the
> > SelectedIndexChanged event.
 
 
John





PostPosted: Fri Oct 31 13:01:51 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? "Didn't work" how?

--
John

"Mary Kerrigan" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Here's one thing I have tried which didn't work:
>
> Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
> e As System.EventArgs) Handles MyList.SelectedIndexChanged
>
> Dim myListItem As DataListItem = CType(sender,
> DataList).SelectedItem
> Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
> Dim myValue As String = myHyperlink.Text
> lblTest.Text = myValue
>
> End Sub
>
>
>
>
> EMail@HideDomain.com (Mary Kerrigan) wrote in message
news:<EMail@HideDomain.com>...
> > OK - I know how to assign a value to the public property, but what I
> > can't figure out is the syntax to retrieve the Text attribute's value
> > for the selected item. ???
> >
> > "John Saunders" <john.saunders at surfcontrol.com> wrote in message
news:<OfK$EMail@HideDomain.com>...
> > > "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> > > news:EMail@HideDomain.com...
> > > > I have a user control (menu) with a data list:
> > > >
> > > > <asp:DataList id="MyList" runat="server">
> > > > <ItemTemplate>
> > > > <asp:hyperlink
> > > > cssclass="MenuUnselected"
> > > > id="myLink1"
> > > > Text='<%# Container.DataItem("Subject") %>'
> > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > Container.DataItem("SubjectID") & "&selection=" &
Container.ItemIndex
> > > > %>'
> > > > runat="server" />
> > > > </ItemTemplate>
> > > > <SelectedItemTemplate>
> > > > <asp:hyperlink
> > > > cssclass="MenuSelected"
> > > > id="myLink2"
> > > > Text='<%# Container.DataItem("Subject") %>'
> > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > Container.DataItem("SubjectID") & "&selection=" &
Container.ItemIndex
> > > > %>'
> > > > runat="server" />
> > > > </SelectedItemTemplate>
> > > > </asp:DataList>
> > > >
> > > > I want to take the value of the Text attribute (the data item:
> > > > "Subject") from the selected item and put it in a label on the
parent
> > > > page. I have spent a day and a half trying this, so I decided to
ask
> > > > if anyone out there can help me. Thanks!
> > >
> > > With ASP.NET, it's best to think a bit object-oriented.
> > >
> > > So, why should your user control know anything about the page it
happens to
> > > be loaded into? In particular, why should it know that there's a label
on
> > > that page? Answer: it shouldn't.
> > >
> > > On the other hand, the user control does know about the Text attribute
of
> > > the selected item. You could define a public property in the user
control
> > > which would expose that Text attribute so that any containing page (or
other
> > > control) can see the value of the Text attribute.
> > >
> > > If the surrounding page needs to know when the selected index has
changed
> > > (so that it knows to fetch the Text property) then you can define a
public
> > > event in your user control and raise it when the user control receives
the
> > > SelectedIndexChanged event.


 
 
mkerrigan





PostPosted: Sat Nov 01 14:25:00 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? Nothing happened - the label was blank instead of showing the value of
the Text attribute of Hyperlink2.

But now I think that's because this is in a user control. The
SelectedIndexChanged does not appear to fire at all. I think it's
because the user control does not postback???

It looks like I will have to go back to the database to get the value
I need when the page reloads... I didn't want to have to do this, you
would think I could get the value from the control, geez, it's right
there on the screen...



"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<O7#E0F#EMail@HideDomain.com>...
> "Didn't work" how?
>
> --
> John
>
> "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > Here's one thing I have tried which didn't work:
> >
> > Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
> > e As System.EventArgs) Handles MyList.SelectedIndexChanged
> >
> > Dim myListItem As DataListItem = CType(sender,
> > DataList).SelectedItem
> > Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
> > Dim myValue As String = myHyperlink.Text
> > lblTest.Text = myValue
> >
> > End Sub
> >
> >
> >
> >
> > EMail@HideDomain.com (Mary Kerrigan) wrote in message
> news:<EMail@HideDomain.com>...
> > > OK - I know how to assign a value to the public property, but what I
> > > can't figure out is the syntax to retrieve the Text attribute's value
> > > for the selected item. ???
> > >
> > > "John Saunders" <john.saunders at surfcontrol.com> wrote in message
> news:<OfK$EMail@HideDomain.com>...
> > > > "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> > > > news:EMail@HideDomain.com...
> > > > > I have a user control (menu) with a data list:
> > > > >
> > > > > <asp:DataList id="MyList" runat="server">
> > > > > <ItemTemplate>
> > > > > <asp:hyperlink
> > > > > cssclass="MenuUnselected"
> > > > > id="myLink1"
> > > > > Text='<%# Container.DataItem("Subject") %>'
> > > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > > Container.DataItem("SubjectID") & "&selection=" &
> Container.ItemIndex
> > > > > %>'
> > > > > runat="server" />
> > > > > </ItemTemplate>
> > > > > <SelectedItemTemplate>
> > > > > <asp:hyperlink
> > > > > cssclass="MenuSelected"
> > > > > id="myLink2"
> > > > > Text='<%# Container.DataItem("Subject") %>'
> > > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > > Container.DataItem("SubjectID") & "&selection=" &
> Container.ItemIndex
> > > > > %>'
> > > > > runat="server" />
> > > > > </SelectedItemTemplate>
> > > > > </asp:DataList>
> > > > >
> > > > > I want to take the value of the Text attribute (the data item:
> > > > > "Subject") from the selected item and put it in a label on the
> parent
> > > > > page. I have spent a day and a half trying this, so I decided to
> ask
> > > > > if anyone out there can help me. Thanks!
> > > >
> > > > With ASP.NET, it's best to think a bit object-oriented.
> > > >
> > > > So, why should your user control know anything about the page it
> happens to
> > > > be loaded into? In particular, why should it know that there's a label
> on
> > > > that page? Answer: it shouldn't.
> > > >
> > > > On the other hand, the user control does know about the Text attribute
> of
> > > > the selected item. You could define a public property in the user
> control
> > > > which would expose that Text attribute so that any containing page (or
> other
> > > > control) can see the value of the Text attribute.
> > > >
> > > > If the surrounding page needs to know when the selected index has
> changed
> > > > (so that it knows to fetch the Text property) then you can define a
> public
> > > > event in your user control and raise it when the user control receives
> the
> > > > SelectedIndexChanged event.
 
 
mkerrigan





PostPosted: Tue Nov 25 15:39:17 CST 2003 Top

ASP.Net >> Put value from DataList on user control to parent page? I have never found an answer to this problem... can anyone please help?


EMail@HideDomain.com (Mary Kerrigan) wrote in message news:<EMail@HideDomain.com>...
> Nothing happened - the label was blank instead of showing the value of
> the Text attribute of Hyperlink2.
>
> But now I think that's because this is in a user control. The
> SelectedIndexChanged does not appear to fire at all. I think it's
> because the user control does not postback???
>
> It looks like I will have to go back to the database to get the value
> I need when the page reloads... I didn't want to have to do this, you
> would think I could get the value from the control, geez, it's right
> there on the screen...
>
>
>
> "John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<O7#E0F#EMail@HideDomain.com>...
> > "Didn't work" how?
> >
> > --
> > John
> >
> > "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> > > Here's one thing I have tried which didn't work:
> > >
> > > Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
> > > e As System.EventArgs) Handles MyList.SelectedIndexChanged
> > >
> > > Dim myListItem As DataListItem = CType(sender,
> > > DataList).SelectedItem
> > > Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
> > > Dim myValue As String = myHyperlink.Text
> > > lblTest.Text = myValue
> > >
> > > End Sub
> > >
> > >
> > >
> > >
> > > EMail@HideDomain.com (Mary Kerrigan) wrote in message
> news:<EMail@HideDomain.com>...
> > > > OK - I know how to assign a value to the public property, but what I
> > > > can't figure out is the syntax to retrieve the Text attribute's value
> > > > for the selected item. ???
> > > >
> > > > "John Saunders" <john.saunders at surfcontrol.com> wrote in message
> news:<OfK$EMail@HideDomain.com>...
> > > > > "Mary Kerrigan" <EMail@HideDomain.com> wrote in message
> > > > > news:EMail@HideDomain.com...
> > > > > > I have a user control (menu) with a data list:
> > > > > >
> > > > > > <asp:DataList id="MyList" runat="server">
> > > > > > <ItemTemplate>
> > > > > > <asp:hyperlink
> > > > > > cssclass="MenuUnselected"
> > > > > > id="myLink1"
> > > > > > Text='<%# Container.DataItem("Subject") %>'
> > > > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > > > Container.DataItem("SubjectID") & "&selection=" &
> Container.ItemIndex
> > > > > > %>'
> > > > > > runat="server" />
> > > > > > </ItemTemplate>
> > > > > > <SelectedItemTemplate>
> > > > > > <asp:hyperlink
> > > > > > cssclass="MenuSelected"
> > > > > > id="myLink2"
> > > > > > Text='<%# Container.DataItem("Subject") %>'
> > > > > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > > > > Container.DataItem("SubjectID") & "&selection=" &
> Container.ItemIndex
> > > > > > %>'
> > > > > > runat="server" />
> > > > > > </SelectedItemTemplate>
> > > > > > </asp:DataList>
> > > > > >
> > > > > > I want to take the value of the Text attribute (the data item:
> > > > > > "Subject") from the selected item and put it in a label on the
> parent
> > > > > > page. I have spent a day and a half trying this, so I decided to
> ask
> > > > > > if anyone out there can help me. Thanks!
> > > > >
> > > > > With ASP.NET, it's best to think a bit object-oriented.
> > > > >
> > > > > So, why should your user control know anything about the page it
> happens to
> > > > > be loaded into? In particular, why should it know that there's a label
> on
> > > > > that page? Answer: it shouldn't.
> > > > >
> > > > > On the other hand, the user control does know about the Text attribute
> of
> > > > > the selected item. You could define a public property in the user
> control
> > > > > which would expose that Text attribute so that any containing page (or
> other
> > > > > control) can see the value of the Text attribute.
> > > > >
> > > > > If the surrounding page needs to know when the selected index has
> changed
> > > > > (so that it knows to fetch the Text property) then you can define a
> public
> > > > > event in your user control and raise it when the user control receives
> the
> > > > > SelectedIndexChanged event.