I'm sure I'm just being stupid - User Co

Results 1 to 2 of 2

Thread: I'm sure I'm just being stupid - User Co

  1. #1
    Join Date
    Dec 1969

    Default I'm sure I'm just being stupid - User Co

    Dear Everyone,<BR><BR>I have been trying unsuccessfully for the last few hours to get my the datagrid in a user control<BR>embedded in my web form to talk to my web form one way or another. <BR><BR>The first approach I tried was a delegate function. I set up the user control to include a delegate<BR><BR>public delegate void CodeUpdater(String FieldKey, String UpdatedCode);<BR><BR>then declared an instance inside my user control as<BR><BR>private CodeUpdater cu;<BR>public CodeUpdater SetCodeUpdater<BR>{<BR> set<BR> {<BR> this.cu = value;<BR> }<BR>}<BR><BR>and then inside the handler for the SelectedIndexChanged event<BR><BR>private void indexChanged(object sender, EventArgs e)<BR>{<BR> if(this.cu != null)<BR> this.cu("Blah", "Blah");<BR>}<BR><BR>then from the web forms page I find the user control on the web page and set the option<BR><BR>cvChooser = this.FindControl("cvChooser");<BR>cvChooser.SetCod eUpdater = new CodeUpdater(this.updateCodes);<BR><BR>and this compiles fine, however when the actual event is fired, this.cu is NULL inside indexChanged <BR>and I&#039;m not sure why. After reading all the delegates stuff I eventually decided to take another approach<BR>and try using an event. This time I made public the DataGrid object inside the user control and<BR>from the Web Form explicitily defined <BR><BR>cvChooser.cvGrid.SelectedIndexChanged += new System.EventHandler(this.updateCodes)<BR><BR>this seemed to work, and will work with a method that is inside the user control class if I add the event<BR>handler in InitializeComponent, however this won&#039;t work because I need to pass a different method<BR>in depending on which web form is using the control.<BR><BR>As a last resort I attempted to use an Interface to Make an onUpdateCodes method and implemented <BR>that interface in the Web Form that holds the user control. I then made a reference of that <BR>interface type inside the user control and attempted to call the method required by the interface.<BR>This didn&#039;t work either. I&#039;m up in arms wasting over a day at work on such a trivial stupid problem. <BR>Someone please give me a fresh perspective as I&#039;m sure i&#039;m just doing something stupid. <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Try this article

    http://msdn.microsoft.com/asp.net/using/building/webcontrols/default.aspx?pull=/library/en-us/dnaspp/html/usercontrols.asp<BR><BR>Its written by this guy Scott Mitchell he does stuff with ASP.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts