Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1036739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:45:12+00:00 2026-05-16T14:45:12+00:00

I have a page with some datasources in it. I am doing reenginering of

  • 0

I have a page with some datasources in it. I am doing reenginering of the page itself and would like to split some parts of the page in several user controls.

In my code I have an ObjectDataSource object with the following params

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
   TypeName="DataSetTableAdapters.PhotosTableAdapter"
   SelectMethod="GetPhotosForAlbum">
   <SelectParameters>
       <asp:ControlParameter Name="albumID" ControlID="txtAlbumID" Type="Int32"/>
   </SelectParameters>
</asp:ObjectDataSource>

This piece of code automatically bind the hidden field “txtAlbumId” to the datasource. In my revision this datasource should be moved to a user control.

What is the best way to handle a scenario like this?

Regards,
Lorenzo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:45:12+00:00Added an answer on May 16, 2026 at 2:45 pm

    You can create a property on the user control to expose the property on the hidden field like so:

    public int AlbumID
    {
        get { return Convert.ToInt32(txtAlbumID.Value); }
        set { txtAlbumID.Value = value.ToString(); }
    }
    

    You should then be able to wire the object data source to the user control:

    <asp:ControlParameter Name="albumID" ControlID="myUserControl" PropertyName="AlbumID" Type="Int32"/>
    

    Edit:

    There are a few ways to go the other way around (i.e., data source in the user control). One approach is viable, but I find makes for some designer confusion, is to expose the parameter collection from the user control as a public property:

    public ParameterCollection SelectParameters
    {
        get { return ObjectDataSource1.SelectParameters; }
    }
    

    Doing so allows you to fill the parameter collection from the page like so:

    <my:UserControl runat="server" ID="myUserControl">
        <SelectParameters>
            <%-- ... --%>
        </SelectParameters>
    </my:UserControl>
    

    If you use a designer, your control will always display an error, but it works. (Note, that I’ve used this approach with query string and session parameters. It would be interesting to see if it will survive control parameters.)

    I think, though, that the easiest method is to swap out your ControlParameter for a plain old Parameter, and expose the default value through a property.

    public int AlbumID
    {
        get { return Convert.ToInt32(ObjectDataSource1.Parameters[0].DefaultValue); }
        set { ObjectDataSource1.Parameters[0].DefaultValue = value.ToString(); }
    }
    

    You can then data bind or assign directly to the AlbumID property of the control, and expect the value to be forwarded to the parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one aspx page with some controls. Also i have one DIV which
I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
I have this code in the page load...For some reason the dropdown binds to
I have an HTML page with some <code> segments, and I have given them
We have a page which requires user to enter some input and post submission
I have several Fusioncharts on my page and some of them are outside the
I have a page with several Ajax.InPlaceEditor fields. Some are single line (text input
I have a page with some dynamically added buttons. If you click a button
I have a page where when some operation goes wrong i want to start
I have a page where I submit some data, and return to the original

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.