CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Location
    SW FLorida
    Posts
    8

    Unhappy C# Eventargs / Overloading / Delegates ?

    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
    Doin' the Shift-Click Drag ....

  2. #2
    Join Date
    Jun 2002
    Location
    SW FLorida
    Posts
    8

    Question

    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
    Doin' the Shift-Click Drag ....

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured