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 6022463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:51:41+00:00 2026-05-23T03:51:41+00:00

I’m writing item template for repeater in separate control, and then I’m using following

  • 0

I’m writing item template for repeater in separate control, and then I’m using following code:

HospitalRepeater.DataSource = LocationsList;
HospitalRepeater.ItemTemplate = Page.LoadTemplate("~/UserControls/HospitalDetails.ascx");
HospitalRepeater.DataBind();

This code worked fine, however now we want to add custom events to HospitalDetails control.

We created following event with custom event args:

public class HospitalItemEventArgs : EventArgs
{
    public Int32 HospitalID { get; set; }

    public HospitalItemEventArgs() { }

    public HospitalItemEventArgs(Int32 hID)
    {
        this.HospitalID = hID;
    }
}


public event EventHandler<HospitalItemEventArgs> HospitalAction;

protected virtual void OnHospitalAction(HospitalItemEventArgs e)
{
    if (HospitalAction!= null)
        this.HospitalAction(this, e);
}

Now here is a problem – I can’t access this custom event from my code after loading this control as template, because it returns object of System.Web.UI.ITemplate.
I assumed that this is wrapper above my exact control, but this assumtion is wrong.

Cast to my control type fails with following error message:

Unable to cast object of type 'SimpleTemplate' to type 'UserControls.HospitalDetails'.

I’ve tried reverse action – load control using

Page.LoadControl("~/UserControls/HospitalDetails.ascx");

It returns object of correct HospitalDetails type, but It does not implement ITemplate interface.

Whan I tried to do that I’ve received error message:

Unable to cast object of type 'ASP.usercontrols_hospitaldetails_ascx' to type 'System.Web.UI.ITemplate'.

Can anyone help me to deal with this cast, or find another solution which matches following requrements:

  • Repeater should be bound to list of HospitalItems to display details.
  • Template for displaying details should hide it’s UI interactions and expose few simple events like HospitalAction with hospital ID.
  • Separate object must have ability to subscribe to this events.
  • 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-23T03:51:42+00:00Added an answer on May 23, 2026 at 3:51 am

    Your best bet is probably to create some <asp:Button /> controls specifying the CommandName and CommandArgument attributes. You can then handle the bubbled even on the repeater itself, interrogate the arguments for CommandName and CommandArgument.

    I’m not using a separate control as a template but the same thing can be accomplished like this.

    <asp:Repeater ID="myRepeater" runat="server">
        <ItemTemplate>
            <asp:Button ID="SaveButton"
                        CommandName="Save" 
                        CommandArgument="{insert hospitol ID here}" 
                        Text="Save"
                        runat="server" />
        </ItemTemplate>
    </asp:Repeater>
    
        void myRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                //Do some saving
            }
        }
    

    Update

    The purpose for the button’s CommandArgument and CommandName attributes is to allow you to provide the user with individual actions to take on databound ui content. The CommandArgument attribute is to allow you a point of entry back into the data to retrieve the relevant information for the event. I have never tried to put multiple values in this attribute, but I do not see a reason why it would not work.

    Another option is to create a separate list that contains HospitalID and DoctorID associations, create a unique ID for each association and store that list in a database (if you need to persist it), cache (if used by multiple users), session (if used by multiple pages by same user) or Viewstate (if used by a single page and the list is relatively short).

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.