oh, you know what, I had the subscription code after my postback test. I
just had to move it up above so I resubscribe
on each postback. And, your solution would have worked too.
Thanks for your help.
T
"Sazid Khan" <(E-Mail Removed)> wrote in message
news:0A737E51-FBEE-4A5A-AF18-(E-Mail Removed)...
>
> Hi Tina,
>
> the code looks neat except for the fact : event should be assigned in the
> OnInit() not OnLoad().
>
> Move
>
> myEG.RaiseCFEvent += new
> EditGrid.ChangedFieldsEventHandler(this.HandleChangedEvent); }
>
> in the default.aspx.cs to
>
> override protected void OnInit(EventArgs e)
> {
> InitializeComponent();
> base.OnInit(e);
> }
>
> private void InitializeComponent()
> {
> myEG.RaiseCFEvent += new
> ChangedFieldsEventHandler(this.HandleChangedEvent);
> this.Load += new System.EventHandler(this.Page_Load);
> }
>
> Thanks,
> Sazid.
>
> "Tina" wrote:
>
>> (my last post was incomplete so this issue is being reposted)
>>
>> I have an ASP.Net C# app with a Default.aspx page with an ascx user
>> control
>> on the page named EditGrid.ascx given the ID myEG on the page.
>>
>>
>> I am trying to raise a custom event in this user control passing custom
>> data
>> arguments. I have done this many times in VB but this is my first time
>> in
>> C#.
>>
>> In the default.aspx page I have the following code to subscribe to the
>> event
>> along with an empty method to handle the event:
>> protected void Page_Load(object sender, EventArgs e)
>> {
>> if (!IsPostBack){
>>
>> myEG.RaiseCFEvent += new
>> EditGrid.ChangedFieldsEventHandler(this.HandleChangedEvent); }
>>
>> }
>>
>>
>> protected void HandleChangedEvent(object sender,
>> ChangedFieldsEventArgs
>> e)
>> {
>> string myString = "debug";
>> }
>>
>>
>> The code below, in the ascx control, passes the proper arguments in the
>> this.OnRaiseCFEvent(myArgs); code but in the OnRaiseCFEvent method
>> RaiseCFEVent is always null so this.RaiseCFEvent(this,e); never executes.
>>
>> Can anyone tell my why RaiseCFEvent is always null? As you can see there
>> is
>> a subscriber
>> to the event.
>> thanks,
>> T
>>
>> public partial class EditGrid : System.Web.UI.UserControl
>> {
>> public delegate void ChangedFieldsEventHandler(object sender,
>> ChangedFieldsEventArgs e);
>> public event ChangedFieldsEventHandler RaiseCFEvent;
>> protected virtual void OnRaiseCFEvent(ChangedFieldsEventArgs e)
>> {
>> if (this.RaiseCFEvent != null)
>> {
>> this.RaiseCFEvent(this,e);
>> }
>> }
>> ..
>> ..
>> ..
>> ChangedFieldsEventArgs myArgs = new
>> ChangedFieldsEventArgs(gvRow.RowIndex, i, string1, string2);
>> this.OnRaiseCFEvent(myArgs);
>>
>> ..
>> ..
>> ..
>>
>> }
>>
>> public class ChangedFieldsEventArgs : EventArgs
>> {
>> public readonly int row, col;
>> public readonly string newVal, oldVal;
>> public ChangedFieldsEventArgs(int row, int col, string newVal, string
>> oldVal)
>> {
>> this.row = row;
>> this.col = col;
>> this.newVal = newVal;
>> this.oldVal = oldVal;
>> }
>> }
>>
>>
>>
|