Link to home
Create AccountLog in
Avatar of dejandejanovic
dejandejanovic

asked on

Need click button twice to execute code behind under UpdatePanel control. Need someone to check code.

Hello,
I have strange issue, for which I'm not able to found bottom. I have simple contact form, which I have done many times so far, without problem. I have add an UpdatePanel control, and now need click 2x button to execute code behind.
But, If I remove UpdatePanel, ScriptManager, etc, then button works fine with only one click.
Again, it is very strange for me, as I have almost copy code from another solution, and past into this one.

<body style="width: 456px">
    <form id="form1" runat="server" style="background-image: url('background.jpg'); background-repeat: no-repeat; width: 556px; height: 610px;">
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
        <div style="width: 479px;  height: 548px; margin-left: 16px;">
           
                
                            <table class="auto-style1">
            <tr>
                <td class="auto-style5"></td>
                <td class="auto-style9"></td>
                <td class="auto-style8"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Podjetje:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style10">
                    <asp:TextBox ID="TextBoxCompany" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelCompany" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Ime in priimek:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxName" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelName" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style7"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>E-mail:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxEmail" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelEmail" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Telefon:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxPhone" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelPhone" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Storitev:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style10">
                    <asp:DropDownList ID="DropDownListService" runat="server" BackColor="#C6C6D9" Font-Size="Medium" Height="23px" Width="224px">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>IT TELEKOMUNIKACIJE</asp:ListItem>
                        <asp:ListItem>IT INFRASTRUKTURA</asp:ListItem>
                        <asp:ListItem>IT REŠITVE</asp:ListItem>
                        <asp:ListItem>IT SPLETKO</asp:ListItem>
                        <asp:ListItem>IT REPORTING</asp:ListItem>
                        <asp:ListItem>IT SECURITY</asp:ListItem>
                    </asp:DropDownList>
                    <asp:Label ID="LabelService" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Zadeva:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxSubject" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelSubject" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style12"><strong>Sporocilo:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style13">
                    <asp:TextBox ID="TextBoxMessage" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="332px" Font-Size="Medium" Height="169px" TextMode="MultiLine"></asp:TextBox>
                </td>
                <td class="auto-style14">
                    <asp:Label ID="LabelMessage" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Koliko je 2x2:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxCaptcha" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="30px" Font-Size="Medium" Height="23px" style="text-align: center"></asp:TextBox>
                    <asp:Label ID="LabelCaptcha" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:Label ID="LabelValidation" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Red"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:Button ID="btnSend" runat="server" BackColor="#2C5A9A" CssClass="button" ForeColor="White" Text="POŠLJI" Width="108px"  />
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                        <ProgressTemplate>
                        <img alt="" class="auto-style15" src="ajax-loader.gif" /></td>
                        </ProgressTemplate>
                         </asp:UpdateProgress>
                    <td class="auto-style2">&nbsp;</td>
            </tr>
        </table>
     </div>  
                </ContentTemplate>
            </asp:UpdatePanel>
    </form>
</body>

Open in new window


Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
        If TextBoxCompany.Text = "" Then
            LabelCompany.Visible = True
            LabelValidation.Text = "Obvezna polja so prazna!"
            LabelValidation.ForeColor = Drawing.Color.Red
        Else
            LabelCompany.Visible = False


            If TextBoxName.Text = "" Then
                LabelName.Visible = True
                LabelValidation.Text = "Obvezna polja so prazna!"
                LabelValidation.ForeColor = Drawing.Color.Red
            Else
                LabelName.Visible = False

                If TextBoxEmail.Text = "" Then
                    LabelEmail.Visible = True
                    LabelValidation.Text = "Obvezna polja so prazna!"
                    LabelValidation.ForeColor = Drawing.Color.Red
                Else
                    LabelEmail.Visible = False

                    Dim FoundMatch As Boolean
                    Try
                        FoundMatch = Regex.IsMatch(TextBoxEmail.Text, "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")
                    Catch ex As Exception
                    End Try
                    If Not FoundMatch Then
                        LabelEmail.Visible = True
                        LabelValidation.Text = "Poštni naslov je nepravilen!"
                        LabelValidation.ForeColor = Drawing.Color.Red
                    Else
                        LabelEmail.Visible = False

                        If TextBoxPhone.Text = "" Then
                            LabelPhone.Visible = True
                            LabelValidation.Text = "Obvezna polja so prazna! "
                            LabelValidation.ForeColor = Drawing.Color.Red
                        Else
                            LabelPhone.Visible = False

                            If Not IsNumeric(TextBoxPhone.Text) Then
                                LabelPhone.Visible = True
                                LabelValidation.Text = "Telefon je sestavljen iz številk!"
                                LabelValidation.ForeColor = Drawing.Color.Red
                            Else
                                LabelPhone.Visible = False

                                If DropDownListService.Text = "" Then
                                    LabelService.Visible = True
                                    LabelValidation.Text = "Obvezna polja so prazna!"
                                    LabelValidation.ForeColor = Drawing.Color.Red
                                Else
                                    LabelService.Visible = False

                                    If TextBoxSubject.Text = "" Then
                                        LabelSubject.Visible = True
                                        LabelValidation.Text = "Obvezna polja so prazna!"
                                        LabelValidation.ForeColor = Drawing.Color.Red
                                    Else
                                        LabelSubject.Visible = False

                                        If TextBoxMessage.Text = "" Then
                                            LabelMessage.Visible = True
                                            LabelValidation.Text = "Obvezna polja so prazna!"
                                            LabelValidation.ForeColor = Drawing.Color.Red
                                        Else
                                            LabelMessage.Visible = False

                                            If TextBoxCaptcha.Text = "" Then
                                                LabelCaptcha.Visible = True
                                                LabelValidation.Text = "Obvezna polja so prazna!"
                                                LabelValidation.ForeColor = Drawing.Color.Red
                                            Else
                                                LabelCaptcha.Visible = False

                                                If Not (TextBoxCaptcha.Text) = "4" Then
                                                    LabelCaptcha.Visible = True
                                                    LabelValidation.Text = "Nepravilna verifikacija! Vpiši število 4."
                                                    LabelValidation.ForeColor = Drawing.Color.Red

                                                Else
                                                    LabelCaptcha.Visible = False

                                                    Dim mail As New StringBuilder
                                                    mail.Append("Podjetje: ")
                                                    mail.Append(TextBoxCompany.Text)
                                                    mail.AppendLine()

                                                    mail.Append("Ime in priimek: ")
                                                    mail.Append(TextBoxName.Text)
                                                    mail.AppendLine()

                                                    mail.Append("Email: ")
                                                    mail.Append(TextBoxEmail.Text)
                                                    mail.AppendLine()

                                                    mail.Append("Telefon: ")
                                                    mail.Append(TextBoxPhone.Text)
                                                    mail.AppendLine()

                                                    mail.Append("Storitev: ")
                                                    mail.Append(DropDownListService.Text)
                                                    mail.AppendLine()
                                                    mail.AppendLine()

                                                    mail.Append("Zadeva: ")
                                                    mail.Append(TextBoxSubject.Text)
                                                    mail.AppendLine()
                                                    mail.AppendLine()

                                                    mail.Append("Sporocilo: ")
                                                    mail.AppendLine()
                                                    mail.Append(TextBoxMessage.Text)

                                                    Try
                                                        sendmail("xxxx", mail.ToString())
                                                    Catch ex As Exception
                                                        LabelValidation.Text = "Pojavila se je napaka v povezavi. Na tipkovnici pritisnite tipko F5 ali pa osvežite brskalnik z gumbom osveži! V primeru nadaljnih težav nas poklicite na telefon: xxxxx."
                                                        LabelValidation.ForeColor = Drawing.Color.Red
                                                    End Try
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If


    End Sub
    Protected Sub sendmail(ByVal from As String, ByRef body As String)

        Dim Email As New MailMessage(TextBoxEmail.Text, "xxxxx", "Sporocilo od  " + TextBoxCompany.Text.ToString.ToUpper, body)

        Dim smtpclient As New SmtpClient
        smtpclient.Host = "xxxxx"
        smtpclient.EnableSsl = False
        smtpclient.Port = 587

        Dim credentials As New System.Net.NetworkCredential("xxxxx", "xxxxx")
        smtpclient.Credentials = credentials
        smtpclient.Send(Email)

        LabelValidation.Text = "Sporocilo je uspešno poslano in se zahavaljujemo za Vaše sporocilo na katerega bomo odgovorili v najkrajšem možnem casu."
        LabelValidation.ForeColor = Drawing.Color.DarkGreen
        TextBoxCaptcha.Text = ""

    End Sub

Open in new window


Thanks in advance for help.
ASKER CERTIFIED SOLUTION
Avatar of binaryevo
binaryevo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of dejandejanovic
dejandejanovic

ASKER

Still same issue, need press button twice to execute code behind.
"Always" mode is already as default, but I have try also with "Conditional" + trigger with btnSend button.
From my point it is total illogical.

<body style="width: 456px">
    <form id="form1" runat="server" style="background-image: url('background.jpg'); background-repeat: no-repeat; width: 556px; height: 610px;">
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
        <div style="width: 479px;  height: 548px; margin-left: 16px;">
           
                
                            <table class="auto-style1">
            <tr>
                <td class="auto-style5"></td>
                <td class="auto-style9"></td>
                <td class="auto-style8"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Podjetje:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style10">
                    <asp:TextBox ID="TextBoxCompany" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelCompany" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Ime in priimek:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxName" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelName" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style7"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>E-mail:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxEmail" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelEmail" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Telefon:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxPhone" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelPhone" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Storitev:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style10">
                    <asp:DropDownList ID="DropDownListService" runat="server" BackColor="#C6C6D9" Font-Size="Medium" Height="23px" Width="224px">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>IT TELEKOMUNIKACIJE</asp:ListItem>
                        <asp:ListItem>IT INFRASTRUKTURA</asp:ListItem>
                        <asp:ListItem>IT REŠITVE</asp:ListItem>
                        <asp:ListItem>IT SPLETKO</asp:ListItem>
                        <asp:ListItem>IT REPORTING</asp:ListItem>
                        <asp:ListItem>IT SECURITY</asp:ListItem>
                    </asp:DropDownList>
                    <asp:Label ID="LabelService" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2"></td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Zadeva:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxSubject" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="228px" Font-Size="Medium" Height="23px"></asp:TextBox>
                    <asp:Label ID="LabelSubject" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style12"><strong>Sporocilo:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style13">
                    <asp:TextBox ID="TextBoxMessage" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="332px" Font-Size="Medium" Height="169px" TextMode="MultiLine"></asp:TextBox>
                </td>
                <td class="auto-style14">
                    <asp:Label ID="LabelMessage" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="auto-style3"><strong>Koliko je 2x2:<span class="auto-style4">*</span></strong></td>
                <td class="auto-style11">
                    <asp:TextBox ID="TextBoxCaptcha" runat="server" BackColor="#C6C6D9" BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Width="30px" Font-Size="Medium" Height="23px" style="text-align: center"></asp:TextBox>
                    <asp:Label ID="LabelCaptcha" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Red" Text="!" Visible="False"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:Label ID="LabelValidation" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Red"></asp:Label>
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:Button ID="btnSend" runat="server" BackColor="#2C5A9A" CssClass="button" ForeColor="White" Text="POŠLJI" Width="108px"  />
                </td>
                <td class="auto-style2">&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td class="auto-style11">
                    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                        <ProgressTemplate>
                        <img alt="" class="auto-style15" src="ajax-loader.gif" /></td>
                        </ProgressTemplate>
                         </asp:UpdateProgress>
                    <td class="auto-style2">&nbsp;</td>
            </tr>
        </table>
  
    </div>  
                    </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnSend" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
    </form>
</body>

Open in new window