[Mono-bugs] ImageButton Command event always raised

Yves Darmaillac ydarmaillac at nourysolutions.com
Fri Sep 30 05:56:50 EDT 2005


Strange behaviour with ImageButton class ! The Command event is raised 
whatever the action in the form ...

Exemple :



<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>
<script language="C#" runat="server">
    static int count = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        Console.WriteLine("******** {0} ********", ++count);
        Message.Text = "";
    }
   
    protected void SubmitBtn1_Command(object sender, CommandEventArgs e)
    {
        Console.WriteLine("-- {0} : {1} --", ((WebControl) sender).ID, 
e.CommandName);
        Console.WriteLine("1...");
        Message.Text += "1 !! ";
    }

    protected void SubmitBtn2_Command(object sender, CommandEventArgs e)
    {
        Console.WriteLine("-- {0} : {1} --", ((WebControl) sender).ID, 
e.CommandName);
        Console.WriteLine("2...");
        Message.Text += "2 !! ";
    }

    protected void DDList1_IndexChanged(object sender, EventArgs e) {
        Console.WriteLine("-- {0} --", ((WebControl) sender).ID);
        Console.WriteLine("{0}...", ((DropDownList) sender).SelectedValue);
        Message.Text += String.Format("{0} !! ", ((DropDownList) 
sender).SelectedValue);
    }

    protected void SubmitBtn6_Command(object sender, CommandEventArgs e)
    {
        Console.WriteLine("-- {0} : {1} --", ((WebControl) sender).ID, 
e.CommandName);
        Console.WriteLine("6...");
        Message.Text += "6 !! ";
    }
</script>
</head>
<body>
   <form runat="server" method="get">

      <h3>TESTS</h3>

      Click !<br><br>
 
    <table><tr>
      <td><asp:ImageButton id="SubmitBtn1"
               ImageUrl="images/1.png"
               OnCommand="SubmitBtn1_Command"
               CommandName="C1"
               runat="server"/></td>

      <td><asp:ImageButton id="SubmitBtn2"
               ImageUrl="images/2.png"
               OnCommand="SubmitBtn2_Command"
               CommandName="C2"
               runat="server"/></td>

       <td><asp:DropDownList id="DDList1"
                AutoPostBack="True"
                OnSelectedIndexChanged="DDList1_IndexChanged"
                Font-Name="Courier" ForeColor="green" Font-Size="25" 
Font-Bold="true" Width="70"
                runat="server">
                   <asp:ListItem id = "i3" runat = "server">3</asp:ListItem>
                   <asp:ListItem id = "i4" runat = "server">4</asp:ListItem>
                   <asp:ListItem id = "i5" runat = "server">5</asp:ListItem>
       </asp:DropDownList></td>

       <td><asp:Button id="SubmitBtn6"
                Text="6"
                Font-Name="Courier" ForeColor="blue" Font-Size="25" 
Font-Bold="true" Width="70"
               OnCommand="SubmitBtn6_Command"
               runat="server"/></td>

    </tr></table>

      <p>

      <asp:label id="Message" runat="server"/>

   </form>
</body>
</html>



More information about the mono-bugs mailing list