firing imagebutton control inside panel

Wigging
Wigging used Ask the Experts™
on
when i click on submit on my imagebutton control, my code runs before my required field validators?  i am thinking it is related of being inside the panel.  

could you look at my code below???
<asp:Panel ID="Panel1" runat="server">
    <table cellpadding="3" cellspacing="0" border="0">
        <tr>
            <td class="subHeading" colspan="2">Add Customer</td>
        </tr>
        <tr>
            <td align="right">
                Name</td>
            <td>
                <asp:TextBox ID="name" runat="server" Columns="30" CssClass="textbox1"/>    
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ErrorMessage="name is required" ControlToValidate="name"></asp:RequiredFieldValidator>      
            </td>
        </tr>
        <tr>
            <td align="right">
                Street</td>
            <td>
                <asp:TextBox ID="address1" runat="server" Columns="45" CssClass="textbox1"/>          
              <asp:RequiredFieldValidator ControlToValidate="address1" ID="RequiredFieldValidator2" 
                    runat="server" ErrorMessage="Street required." /></td>
        </tr>
        <tr>
            <td align="right">
                Apt/Building/Suite</td>
            <td>
                <asp:TextBox ID="address2" runat="server" Columns="45" CssClass="textbox1"/></td>
        </tr>
        <tr>
            <td align="right">
                City</td>
            <td>
                <asp:TextBox ID="city" runat="server" Columns="30" CssClass="textbox1"/>          
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ControlToValidate="city" ErrorMessage="City required."></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td align="right">
                State</td>
            <td>
                <asp:TextBox ID="state" runat="server" Columns="5" MaxLength="2" CssClass="textbox1"/>          
              <asp:RequiredFieldValidator ControlToValidate="state" ID="RequiredFieldValidator4" 
                    runat="server" ErrorMessage="State required." /></td>
        </tr>
        <tr>
            <td align="right">
                Zip</td>
            <td>
               <asp:TextBox ID="zip" runat="server" Columns="10" CssClass="textbox1"/>          
              <asp:RequiredFieldValidator ControlToValidate="zip" ID="RequiredFieldValidator5" 
                    runat="server" ErrorMessage="Zip Code required." /></td>
        </tr>
        <tr>
            <td align="right">
                Country</td>
            <td>
                <asp:DropDownList ID="country" runat="server"   DataTextField="country" DataValueField="country" Width="230" CssClass="textbox1"></asp:DropDownList>  </td>
        </tr>
        <tr>
            <td align="right">
                Email</td>
            <td>
                <asp:TextBox ID="email" runat="server" Columns="30" CssClass="textbox1"/>          
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                    ControlToValidate="email" ErrorMessage="Email required."></asp:RequiredFieldValidator>
                &nbsp;<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
                    runat="server" ControlToValidate="email" ErrorMessage="wrong format" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td align="right">
                Retype Email</td>
            <td>
                <asp:TextBox ID="verifyEmail" runat="server" Columns="30" CssClass="textbox1"/>          
                &nbsp;<asp:RequiredFieldValidator ControlToValidate="verifyEmail"  Display="None"  ID="reqVerEmail" runat="server" Text="Email verify required." /></td>
        </tr>
        <tr>
            <td align="right">
                Phone</td>
            <td>
                (<asp:TextBox ID="areacode" runat="server" Columns="3" MaxLength="3" CssClass="textbox1"/>)
                <asp:TextBox ID="phone" runat="server" Columns="7" CssClass="textbox1"/>Ex: (xxx) xxx-xxxx </td>
        </tr>
        <tr>
            <td align="right">
                &nbsp;</td>
            <td>
              <asp:CheckBox ID="contactCustomer" runat="server" Text='Please have a Sawmill Consultant contact me.' />
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="right">
                &nbsp;</td>
            <td>
                <asp:ImageButton ID="ImageButton1" runat="server" 
                    ImageUrl="~/images/submit.png" />
                
            </td>
        </tr>
    </table>
    </asp:Panel>



code behind
  Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click

        If name.Text <> "" And zip.Text <> "" Then
            ParseInputs()
            FillGrid()
        Else
            Label1.Text = " name and zip must be filled"
        End If



        ' Response.Redirect("omCSwelcome.aspx")

    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Commented:
Add this to the top of ImageButton1_Click.

Page.Validate()
If Not Page.IsValid Then Exit Sub

Open in new window

Top Expert 2013

Commented:
One reason is your browser JavaScript is disabled. So your clientside validation is not done and your server-side validation and code is executed but since page.isvalid will be false your validators will display the message.
So:
1: Enable Browser Javascript
2: Enclose you code like below:


 Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click

       'If page is valid then only execute the code
 If Page.IsValid Then
        If name.Text <> "" And zip.Text <> "" Then
            ParseInputs()
            FillGrid()
        Else
            Label1.Text = " name and zip must be filled"
        End If
        ' Response.Redirect("omCSwelcome.aspx")
    End If
End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial