Click to See Complete Forum and Search --> : C# Eventargs / Overloading / Delegates ?


JimH
July 2nd, 2002, 04:04 PM
A newbie question ... I have a Web Forms project in which panels simulate sequential forms pages.

I have image buttons in the initial page for the user to select a preference.

I have onclick event handlers which are supposed to communicate a unique value, used to initialize / encode other pages.

The code fragments show one event handler -- ImgBtn0_Click() -- within the <head> tag of my .aspx file.

This handler is called OK; the problem is to pass a value -- the test string "0", say, as the System.Eventargs value to the panel switcher btn_next0() in my .aspx.cs file.

I am aware that I am attempting -- and failing -- to overload btn_next0(), I also suspect that the solution involves using delegates.

I have read six or seven web articles -- MSDN and elsewhere -- which supposedly elucidate this subject, but I do not see how to apply them here.

Advice -- the more detailed and explicit the better -- will be greatly appreciated.

(Failing to compile) code fragments follow:
-----------------------------------------------------------------------

<head>
<script language="C#" runat="server">
void ImgBtn0_Click(object sender, ImageClickEventArgs e) {
btn_Next0(sender, "0");
}
</head>

<body>
<form id="Form1" name="Form1" action="WebForm1.aspx" method="post" runat="server">

<asp:Panel ID="Panel0" Runat="server">
<asp:Label ID="lblPanel1" Runat="server" Text="X" />
<asp:ImageButton id="ImgBtn0" runat="server" ImageUrl="/../../../images/button.jpg" OnClick="ImgBtn0_Click" />

</panel>

</form>
</body>

public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// User code to initialize first page
Panel0.Visible = true;
Panel1.Visible = false;
}
public void btn_Next0(object sender, System.EventArgs e)
{
// User code to initialize second page
Panel0.Visible = false;
Panel1.Visible = true;
lblPanel1.Text = "Value is " + e;
}

-----------------------------------------------------------------------
JimH

JimH
July 3rd, 2002, 01:17 PM
Maybe there is a simple way to solve this -- it's just that I don't know enough yet about the significance and use of the Sender and EventArgs parameters.

Can the .aspx.cs handler btn_next0 recognise which particular button was the sender?

In other words, is there a way to extract the ID of ImgBtn0 or whatever from the 'object sender' parameter?

JimH