473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Raise Event in User Control and Catch in a Page

3
Hi I have been trying to raise an event in the user control. The problem is I always get null reference in the event and my event never gets fired. Can someone help me?
The Code I have written is as follows:

// Decelerating the delegate and event

public delegate void OnButtonClick(string strValue);
public event OnButtonClick OtherMonth;

protected void Page_Load(object sender, EventArgs e)
{

// Raising the event from a button click
// Check if event is null
if (OtherMonth != null)
OtherMonth(string.Empty);

In the Page where I need to catch the event
protected void Page_Load(object sender, EventArgs e)
{
displayInfo.OtherMonth += new UserControls_displayinfo.OnButtonClick(displayInfo _OtherMonth);


Finallying Handeling the Event
private void displayInfo_OtherMonth(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
// Do some thing
}
Sep 10 '07 #1
3 1609
Are u wanting to catch the event in the other page?
as far as I know, asp .net won't do that

I 'd rather do this:
in the function that handle button_click put something like this
this.Response.Redirect("otherPage.aspx?value=5");

then catch it in the otherPage.aspx load function
int theValue = Convert.ToInt32(this.Request.QueryString.Get("valu e"));
Sep 10 '07 #2
Rastra
3
Hi,
Thanks for the answer but that will not help me. I have a user control in a page and I want to raise an even in the user control and catch it in the page containing the user control. I have seen a lot of post with examples for this but my problem is that the event is always null. What I have missed or did do wrong. I would appricate if some one could help me in fixing the problem.
Sep 10 '07 #3
Plater
7,872 Expert 4TB
Your delegate declaration type does not appear to match your implementation.
Which would probably give you a null reference exception.
Sep 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
1
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them)....
2
by: Tina | last post by:
(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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.