Note that there are some explanatory texts on larger screens.

plurals
  1. PORepeater template control with custom events
    primarykey
    data
    text
    <p>I'm writing item template for repeater in separate control, and then I'm using following code:</p> <pre><code>HospitalRepeater.DataSource = LocationsList; HospitalRepeater.ItemTemplate = Page.LoadTemplate("~/UserControls/HospitalDetails.ascx"); HospitalRepeater.DataBind(); </code></pre> <p>This code worked fine, however now we want to add custom events to HospitalDetails control.</p> <p>We created following event with custom event args:</p> <pre><code>public class HospitalItemEventArgs : EventArgs { public Int32 HospitalID { get; set; } public HospitalItemEventArgs() { } public HospitalItemEventArgs(Int32 hID) { this.HospitalID = hID; } } public event EventHandler&lt;HospitalItemEventArgs&gt; HospitalAction; protected virtual void OnHospitalAction(HospitalItemEventArgs e) { if (HospitalAction!= null) this.HospitalAction(this, e); } </code></pre> <p>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.</p> <p>Cast to my control type fails with following error message:</p> <pre><code>Unable to cast object of type 'SimpleTemplate' to type 'UserControls.HospitalDetails'. </code></pre> <p>I've tried reverse action - load control using</p> <pre><code>Page.LoadControl("~/UserControls/HospitalDetails.ascx"); </code></pre> <p>It returns object of correct HospitalDetails type, but It does not implement ITemplate interface.</p> <p>Whan I tried to do that I've received error message:</p> <pre><code>Unable to cast object of type 'ASP.usercontrols_hospitaldetails_ascx' to type 'System.Web.UI.ITemplate'. </code></pre> <p>Can anyone help me to deal with this cast, or find another solution which matches following requrements:</p> <ul> <li>Repeater should be bound to list of HospitalItems to display details.</li> <li>Template for displaying details should hide it's UI interactions and expose few simple events like HospitalAction with hospital ID.</li> <li>Separate object must have ability to subscribe to this events.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload