Excuse me for chiming in here, but if you're trying to databind the syntax is
this: '<%# NewsItemId %>' (# instead of =), presuming NewsItemId is publicly
accessible (else you might use container.dataitem.NewsItemId if it's coming
from a datasource).
Or you can do it in the code-behind as Karl says. If there's only one
instance of the user control (i.e. it's not a bunch of them in a grid), I
wouldn't bother with databinding, just set the control in the code, e.g. the
user control exposes property NewsItemId, and the parent page sets the value
of that control where it makes sense. Or, on load of the user control, you
can go get the NewsItemId from the parent page, but imho it's generally weak
design for the user control to count on the internals of the parent page
(also, don't forget that init of the user controls happens before init of the
page, but load of the controls happens *after* load of the page).
To make your original example work, in the user control I'd do (vb syntax):
dim myPage as parentPageClass = ctype(me.page, parentPageClass)
dim itemId as integer = convert.toint32(myPage.NewsItemId)
You need to cast the page of the user control to whatever its real type is,
else the system can't know it's got a NewsItemId property.
hth,
Bill
"Pete Davis" wrote:
I think we're really miscommunicating here.
You provided the code:
page_load
Comments1.ItemId = newsItemId
end sub
So my question is: Where does newsItemId come from? Originally, it's in the
page code behind.. I can't get it into the attributes for the UserControl
the way I'm trying (please see original question as to why).
The page you referred me to shows how to send static attributes to a user
control, but my attribute is dynamic.
So I'm still not sure what you're trying to tell me.
Pete
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:er**************@TK2MSFTNGP15.phx.gbl... You can take a look at:
http://www.openmymind.net/index.aspx?documentId=9#3.1
But why does the comment's user control need to know WHERE the NewsItemId
comes from? It shouldn't. It should simply need to know WHAT it is....
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:1M********************@giganews.com... Okay, but how is the Comments UserControl's CodeBehind going to know what the NewsItemID is from the page's CodeBehind? Does that make sense? The
CodeBehind for the page has the NewsItemID. I'm trying to pass that to the UserControl.
Pete
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
> Pete:
> You normally do all of this in codebehind
>
> in the page, you'd do
>
> page_load
> Comments1.ItemId = newsItemId
> end sub
>
> karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
> news:q6********************@giganews.com...
> > I'm fairly weak with ASP.NET. What I'm trying to do is pass an
> > attribute
> > to
> > a UserControl. The attribute is a value from the CodeBehind for the
page.
> >
> > So in my .aspx I have the following:
> >
> > <cm:Comments runat="server" ID="Comments1" CommentType="News"
ItemID="<%=
> > NewsItemID %>" />
> >
> > NewsItemID is a property in the CodeBehind for the page.
> >
> > However when I get to the Page_Load of the UserControl and do the
> > following:
> >
> > int itemID = Convert.ToInt32(this.Attributes["ItemID"]);
> >
> > it throws an exception because the value of this.Attributes["ItemID"]
> > is
> > <%=
> > NewsItemID %>
> >
> > Obviously, not what I wanted.
> >
> > Is there a proper way to do this?
> >
> > Thanks.
> >
> > Pete
> >
> >
>
>