Gallery admin thumbnail control


M

mc

I'm writing a gallery app with an online update facility, I would like
to be able to create a custom Thumbnail control, which will display the
thumbnail and an expandable panel with the meta data which the user can
subsequently update.

I've created the control and added an Image.

I also have a property for the "PhotoId", which when queried in the
database will return the image location and the meta data.

When in the control creation "Life cycle" can I use the property value,
if someone is using the control in a data bound repeater as such: -

<repeater>
<itemTemplate>
<mc:photoThumb runat="server" ID="photoThumbnail" PhotoId='<%#
Eval("PhotoID")%>'/>
</itemTemplate>
</repeater>

I created an function which pulls the info from the db and updates the
image location and meta data contents. when I call this from the Image
DataBinding event handler, the property has the correct value in it.
This works, but it feels like it's in the wrong place. Where should I be
calling the load data function from?

Any Thoughts?

Regards


MC
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi,

Without your actual code, I'm not sure I fully understand how currently
you're doing.

Is the image data stored in db or just the path of the image stored in db?
When you mean "from the Image DataBinding event handler", do you mean the
Repeater's ItemDataBound event? If this is the case, the PhotoID is
property assigned and you could safely use that to query the data from db
and set other properties accordingly.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

mc

Probably best to ignore all things outside of the web user control!

I have a web user control which contains a <asp:image/>, three
<asp:TextBox/> controls and a PhotoId property.

What I would like to do is instantiate a new instance of this control
using something similar to: -

<mc:photoThumb runat="server" ID="photoThumbnail" PhotoId="1"/>

which when loaded goes to the DB and gets the image location string and
sets the ImageURL and gets each of the three meta data elements and sets
the TextBoxes Text value.

My question is when should I call my function

private void LoadFromDB()

I have called it from the image's DataBinding event, and it works.
However this doesn't seem like the correct place.

Sorry I can't copy the code I do not have access to it from this terminal.

TIA


MC
 
W

Walter Wang [MSFT]

Hi,

The image's DataBinding event will only be fired when your usercontrol is
putting inside a control that is binding to data. You should put the call
to LoadFromDB inside your usercontrol's Load event:

<%@ Control Language="C#" AutoEventWireup="true" ...


protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadFromDB();
}
}

This is assuming your image and TextBox have enabled ViewState; if not
enabled, you should not check Page.IsPostBack and call LoadFromDB() in
every postback.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

mc

If I call the method from the controls Page_Load the Property has not
been initialized yet!

currently I've moved my call to LoadFromDB to the PreRender Event
handler, by which time the Property passed in the markup has been
initialized?

My question still stands, I can make it work by putting it in all sorts
of places, but where is the correct one.

At the Point that Page_Init and Page_Load fire the property has a value
of -1 (the default). Is there an attribute I should be applying to the
property? or any other way to get the property initialized sooner?

Is there a more appropriate group for this question?
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi,

The Page_Load should be fine if the property is assigned in declarative
statement just as you described in your previous example code. However, for
data binding scenario, you're right that in this time the property is not
assigned yet. I'm sorry that I didn't mentioned that previously.

I understand your original question is how to find the correct time to do
the db query. To answer it, we need to know more about the Page's Life
Cycle:

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

From above article, you will see PreRender is the correct place to do this:

<quote>
Before this event occurs:

The Page object calls EnsureChildControls for each control and for the
page.

Each data bound control whose DataSourceID property is set calls its
DataBind method. For more information, see Data Binding Events for
Data-Bound Controls below.

The PreRender event occurs for each control on the page. Use the event to
make final changes to the contents of the page or its controls.
</quote>


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top