none
Conflit entre 2 OnClick RRS feed

  • Question

  • Bonjour;
    Voici le problème:
    J'ai sur mon master page un imagebutton qui permet de changer la redirection vers une autre page lorsqu'il est cliqué (événement Onclick).
    Sur le content page lié à ce master page, j'ai un formulaire, avec un bouton à valider (événement Onclick) pour envoyer ce dernier.
    Je n'arrive pas faire de redirection avec l'image bouton tant que le formulaire n'a pas été rempli et validé. Hors je souhaite laisser le choix à l'utilisateur de faire une redirection, sans forcément remplir et valider le formulaire.
    Je pense qu'il y a un conflit entre le Onclick de l'image button du masterpage et le button du content page.
    Ci-joint le code complet:
    1- frMasterPage.master:
    [CODE]
    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="frMasterPage.master.cs" Inherits="frMasterPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta name="generator" content="Microsoft Visual Studio, see http://msdn.microsoft.com/vstudio/" />
        <meta name="Keywords" content="PrestigeConcepts, Widgets" />
        <meta name="Description" content="About PrestigeConcepts, Inc., it's widgets, employees and company" />
        <meta name="copyright" content="Copyright (c) 2008 PrestigeConcepts, Inc. All rights reserved." />
        <link href="/App_Themes/css-print.css" rel="stylesheet" type="text/css" media="print" />
        <link rel="shortcut icon" href="images/prestige.ico" />
        <title>PrestigeConcepts</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <aspTongue TiediteMapDataSource ID="SiteMapFra" runat="server"
                ShowStartingNode="false" />
            <!--

    TOP INFORMTION
    -->
            <div id="top-information">
                <div>
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/logoprestige.jpg"
                        Width="150px" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:ImageButton ID="ImageButtonDrapeauEn" runat="server"
                        ImageUrl="~/images/drapeauen.jpg" Width="30px" onclick="ImageButtonDrapeauEn_Click"/>
                        &nbsp;
                        <asp:ImageButton ID="ImageButtonDrapeauFr" runat="server"
                        ImageUrl="~/images/drapeaufr.jpg" Width="30px" onclick="ImageButtonDrapeauFr_Click"/>
                 </div>
                <div id="top-information-home">
                    <a href="mailto:info@prestigeconcepts.fr">E-mail</a></div>
                <div id="top-information-phone">
                    tel: (+216)71 82 07 47 </div>
            </div>
            <!--

    TOP NAV

    -->
            <div class="none"><a href="#maincontent">skip to the main content area of this page</a></div>
            <div id="nav-main">
                           <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapFra" Orientation="Horizontal"
                    Width="500px" CssClass="menu-main" MaximumDynamicDisplayLevels="0"
                               StaticSelectedStyle-CssClass="StaticSelectedStyle" >
    <StaticSelectedStyle CssClass="StaticSelectedStyle"></StaticSelectedStyle>
                           </asp:Menu>
                <div>
                    &nbsp;</div>
            </div>
            <a id="maincontent"></a>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
            <!--

    FOOTER

    -->
            <div id="footer">
                Copyright &copy; 2008 PrestigeConcepts, Inc.
                <div>
                    &nbsp;</div>
            </div>
           
        </form>
    </body>
    </html>

    [/CODE]

    2- frMasterPage.master.cs
    [CODE]
    public partial class frMasterPage : System.Web.UI.MasterPage
    {
      protected void ImageButtonDrapeauFr_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Server.Transfer("~/Fra/frDefault.aspx");
        }
        protected void ImageButtonDrapeauEn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Server.Transfer("~/Eng/Default.aspx");
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            SiteMapFra.SiteMapProvider = "Fra";
            SiteMapFra.DataBind();
        }
    }

    [/CODE]



    3- frContact.aspx:
    [CODE]
    <%@ Page Language="C#" MasterPageFile="~/Fra/frMasterPage.master" AutoEventWireup="true" CodeFile="frContact.aspx.cs" Inherits="frContact" Title="Prestige Concepts Inc: Contact" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


        <div id="content-container-three-column">
            <!--

      CONTENT SIDE 1 COLUMN

      -->
            <div id="content-side1-three-column">
                <ul class="list-of-links">
                    <li class="current"><a href="frContact.aspx">Contact</a></li>
                    <li><a href="frDefault.aspx">Accueil</a></li>
                    <li><a href="frProducts.aspx">Produits</a></li>
                      <li><a href="frPartners.aspx">Partenaires</a></li>
                      <li><a href="frReferences.aspx">Réferences</a></li>
                    <li><a href="frAbout.aspx">A propos</a></li>
                    <li><a href="frTestimonials.aspx">Témoignages</a></li>
                </ul>
            </div>
            <!--

      CENTER COLUMN

      -->
            <div id="content-main-three-column">
                <span id="heading">Contact Us</span>
                <hr />
                <h3>
                    Global Headquaters
                </h3>
                <p>
                    Prestige concepts<br />
                    LL1/9-Kortoba Riadh El Andalous<br />
                    2058 Ariana Tunis Tunisie
                </p>
                <p>
                    tel: (+216)71 82 07 47 / (+216)71 82 07 46
                   
                    <br />
                    fax: (+216)71 82 07 48
                </p>
                <a href="mailto:info@prestigeconcepts.com">info@prestigeconcepts.com</a><br />
              
                <p>
                </p>
                <br />
     
                <aspStick out tongueanel ID="Panel1" runat="server" Height="526px" BorderStyle="Dotted" BorderColor="gray"
                    Width="350px" >
                    <table>
                        <caption>
                            <br />
                            <tr>
                                <td style="width: 100px">
                                    Company</td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="txtCompany" runat="server" Width="175px"></asp:TextBox>
                                </td>
                                <td style="width: 100px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
                                        ControlToValidate="txtCompany" ErrorMessage="Please enter your company name">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px">
                                    Name</td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="txtName" runat="server" Width="175px"></asp:TextBox>
                                </td>
                                <td style="width: 100px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                                        ControlToValidate="txtName" ErrorMessage="Please enter your name">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px">
                                    Email</td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="txtEmail" runat="server" Width="175px"></asp:TextBox>
                                </td>
                                <td style="width: 100px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                                        ControlToValidate="txtEmail" ErrorMessage="Please enter your email address">*</asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                                        ControlToValidate="txtEmail"
                                        ErrorMessage="Please enter a valid email (xxx@yyy.zzz)"
                                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px">
                                    Phone
                                </td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="txtPhone" runat="server" Width="175px"></asp:TextBox>
                                </td>
                                <td style="width: 100px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                        ControlToValidate="txtPhone" ErrorMessage="Please enter your phone number">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px; height: 116px;">
                                    Message<span style="font-size: 10pt">*</span>
                                    <br />
                                </td>
                                <td style="width: 100px; height: 116px;">
                                    <asp:TextBox ID="txtMessage" runat="server" Height="106px" TextMode="MultiLine"></asp:TextBox>
                                </td>
                                <td style="width: 100px; height: 116px;">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                                        ControlToValidate="txtMessage" ErrorMessage="Please enter a message">*</asp:RequiredFieldValidator>
                                    <asp:CustomValidator ID="CustomValidator1" runat="server"
                                        ControlToValidate="txtMessage"
                                        ErrorMessage="No more than 1000 characters, no less than 20 characters"
                                        OnServerValidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
                                </td>
                            </tr>
                        </caption>
                    </table>
                  
                   <hr />
                 <asp:Button ID="btnValidate" runat="server" Text="Validate" Width="61px"
                        style="left: 156px; position: relative; top: 10px"
                        OnClick="btnValidate_Click" />&nbsp;<br />
                    <br />
                    <br />
                    <span style="font-size: 7pt">All the fields are compulsory
                        <br />
                        * = Maximum 1000 characters, minimum 20 characters<br />
                        <br />
                        <asp:Label ID="lblError" runat="server"></asp:Label>
                    <br />
                    <br />
                    <br />
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" Height="56px"
                        Width="342px" />
                    </span></aspStick out tongueanel>
                &nbsp;
            </div>
            <!-- END MAIN COLUMN -->
            <!--

      CONTENT SIDE 2 COLUMN

      -->
            <div id="content-side2-three-column">
                <span id="subheading">Prestige Concepts listening you.</span>
                <p>
                <br />
                <br />
                    If you have any question, don't hesitate to contact us. A dynamic and reactive
                    team will answer you quickly.&nbsp;</div>
            <div class="clear">
               
                </div>
               
        </div>
    </asp:Content>


    [/CODE]

    4- frContact.aspx.cs:
    [CODE]
    using System;
    using System.Web.Mail;

    public partial class frContact : System.Web.UI.Page
    {

        protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
        {
            if ((txtMessage.Text.Length < 20) || (txtMessage.Text.Length > 1000))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtName.Text = "";
                txtEmail.Text = "";
                txtCompany.Text = "";
                txtPhone.Text = "";
                txtMessage.Text = "";
               
            }
        }

        protected void btnValidate_Click(object sender, EventArgs e)
        {
            MailMessage email = new MailMessage();
            email.From = "site@prestigeconcepts.fr";
            email.To = "info@prestigeconcepts.fr";
            email.Body =
                "Name :"
                + txtName
                + "\r\n"
                + "Email :"
                + txtEmail
                + "\r\n"
                + "Company: "
                + txtCompany.Text
                + "\r\n"
                + "Phone : "
                + txtPhone.Text
                + "\r\n"
                + "Message : "
                + txtMessage.Text;
            email.Priority = MailPriority.High;

            SmtpMail.SmtpServer = "smtp.planet.tn";

            try
            {
                SmtpMail.Send(email);
                lblError.Text = "Message envoyé avec succès";
              
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }

        }

    }

    [/CODE]

    Merci si vous pouvez m'aider à trouver une solution.
    jeudi 27 décembre 2007 14:52

Toutes les réponses