17
Answers

clander problem with ajaxtoolkit

alaa

alaa

11y
1.4k
1
hi everybody
i have astrange problem with my register page i have a clander which works fine but after i add acode to check user and email if available or not in database its impossble to work only work when i make refresh to the page or start with datetime clander before write the username or email
even loading gif doesnt work
this is my code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="register.ascx.cs" Inherits="UserControl_register"  %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>


<script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.dynDateTime.min.js" type="text/javascript"></script>
<script src="Scripts/calendar-en.min.js" type="text/javascript"></script>
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=Txtbirthday.ClientID %>").dynDateTime({
            showsTime: true,
            ifFormat: "%Y/%m/%d %H:%M",
            daFormat: "%l;%M %p, %e %m, %Y",
            align: "BR",
            electric: false,
            singleClick: false,
            displayArea: ".siblings('.dtcDisplayArea')",
            button: ".next()"
        });
    });
</script>

   <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  
<ContentTemplate>

         <div class="container">
    <section class="register">
      <h1>
          Register on my site</h1>
     
        <div class="reg_section personal_info">
            <asp:Label ID="lbl_msg" runat="server" Text=""></asp:Label>
       </div>

      <div class="reg_section personal_info">
      <h3>Your Personal Information</h3>
       <asp:TextBox ID="Txtusername" placeholder="Your Desired Username" runat="server" OnTextChanged="Txtusername_TextChanged" AutoPostBack="true"></asp:TextBox>
         &nbsp;&nbsp;&nbsp;  <asp:Image ID="ImgUser" runat="server" />
         <h3>Your E_mail</h3>
       <asp:TextBox ID="Txtemail" placeholder="Your E-mail Address"  runat="server" OnTextChanged="Txtemail_TextChanged" AutoPostBack="true"></asp:TextBox>
        &nbsp;&nbsp;&nbsp;  <asp:Image ID="Imgemail" runat="server" />
 
       </div>

      <div class="reg_section password">
      <h3>Your Password</h3>
          <asp:TextBox ID="Txtpassword"  placeholder="Your Password" runat="server" TextMode="Password"></asp:TextBox>
          <asp:TextBox ID="Txtconfrimpass" placeholder="Confirm Password"  runat="server" TextMode="Password"></asp:TextBox>
          <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="Txtpassword" ControlToValidate="Txtconfrimpass" Display="Dynamic" ErrorMessage="password not match" ForeColor="#CC0000"></asp:CompareValidator>
      </div>

      <div class="reg_section password">
      <h3>Your Address</h3>
          <asp:DropDownList ID="ddlcountry" runat="server">
              <asp:ListItem Selected="True">Country</asp:ListItem>
              <asp:ListItem Value="C1">Egypt</asp:ListItem>
              <asp:ListItem Value="C2">Iraq</asp:ListItem>
              <asp:ListItem Value="C3">Palastine</asp:ListItem>
              <asp:ListItem Value="C4">Italy</asp:ListItem>
          </asp:DropDownList>
             
       <asp:TextBox ID="Txtaddress" placeholder="Your address" runat="server"></asp:TextBox>

          <h3>Phone</h3>
        <asp:TextBox ID="Txtphone" placeholder="phone 011-1234567" runat="server"></asp:TextBox>
     
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="invaild phone" ControlToValidate="Txtphone" ForeColor="#CC0000" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"></asp:RegularExpressionValidator>
     
      <div class="reg_section password">

      <h3>Birthday</h3>
        <asp:TextBox ID="Txtbirthday" placeholder="Birthday date" runat="server" ReadOnly="True"></asp:TextBox>
     &nbsp; <asp:Image ID="Imgclander" runat="server" ImageUrl="~/img/calender.png"></asp:Image>
              

      <h3>Gender</h3>
     
          <asp:DropDownList ID="ddlgender" runat="server">
              <asp:ListItem Selected="True">Gender</asp:ListItem>
              <asp:ListItem Value="M">Male</asp:ListItem>
              <asp:ListItem Value="F">Female</asp:ListItem>
            </asp:DropDownList>

           </div>
     
          <div class="reg_section password">
      <h3>Security Question</h3>
     
          <asp:DropDownList ID="ddlsecurityQuestion" runat="server">
              <asp:ListItem Selected="True" Value="Q1">Whats your fathers name ?</asp:ListItem>
              <asp:ListItem Value="Q2">Whats your best book ?</asp:ListItem>
              <asp:ListItem Value="Q3">Whats your best meal ?</asp:ListItem>
              <asp:ListItem Value="Q4">Whats your best fruit ?</asp:ListItem>
              <asp:ListItem Value="Q5">Whats your best channel ?</asp:ListItem>
            </asp:DropDownList>

               <asp:TextBox ID="Txtanswer" placeholder="Your answer" runat="server"></asp:TextBox>

           </div>

<div class="reg_section password">
          <asp:UpdateProgress ID="UpdateProgress1" runat="server">
            <ProgressTemplate>
                <asp:Image ID="Image1" runat="server" ImageUrl="~/img/loading.gif" />
            </ProgressTemplate>
        </asp:UpdateProgress>
    </div>

      </div>
      <p class="terms">
        <label>
            <asp:CheckBox ID="chbaccept" runat="server" />
            I accept  <a href="#">OAAM</a>Terms & Condition
        </label>
      </p>
             &nbsp;&nbsp;&nbsp;
           
             <asp:Button  ID="btnregister" runat="server" Text="Sign Up" BackColor="#AE6CAC" OnClick="btnregister_Click" BorderStyle="None"/>
    </section>
  </div>

    
</ContentTemplate>

</asp:UpdatePanel>


 
  <section class="about">
    This site is powered ##<a href="#">O>


the code behind



public partial class UserControl_register : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void btnregister_Click(object sender, EventArgs e)
    {

        if (chbaccept !=null && chbaccept.Checked)  // to check  if he accept the terms or not
        {
            Member m = new Member();
            lbl_msg.Text = m.Register(Txtusername.Text, Txtemail.Text, Txtpassword.Text, ddlcountry.SelectedValue, Txtaddress.Text, Txtphone.Text, Convert.ToDateTime(Txtbirthday.Text), ddlgender.Text, ddlsecurityQuestion.SelectedValue, Txtanswer.Text);
            //Clear();
        }
        else
        {
            lbl_msg.Text = "please accept the terms";
        }
    }


    protected void Txtusername_TextChanged(object sender, EventArgs e)
    {
      
        Member user = new Member();
       
        if (!string.IsNullOrEmpty(Txtusername.Text))
        {
               if (user.Emailavi(Txtusername.Text))
            {
                ImgUser.ImageUrl = "../NotAvailable.gif";
                lbl_msg.Text = "NotAvailable user";
                lbl_msg.ForeColor = System.Drawing.Color.Red;
                Txtusername.Focus();

            }
            else
            {
                ImgUser.ImageUrl = "../Icon_Available.gif";
                lbl_msg.Text = "Available user";
                lbl_msg.ForeColor = System.Drawing.Color.Green;
            }
        }
    }


    protected void Txtemail_TextChanged(object sender, EventArgs e)
    {
        Member emailcheck = new Member();

        if (!string.IsNullOrEmpty(Txtemail.Text))
        {

                              string email = Txtemail.Text;
                              Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                              Match match = regex.Match(email);
       
        if (match.Success)
    {
       
                if (emailcheck.Emailavi(Txtemail.Text))
            {
                Imgemail.ImageUrl = "../NotAvailable.gif";
                lbl_msg.Text = "NotAvailable email";
                lbl_msg.ForeColor = System.Drawing.Color.Red;

            }
                else
            {
                Imgemail.ImageUrl = "../Icon_Available.gif";
                lbl_msg.Text = "Available email";
                lbl_msg.ForeColor = System.Drawing.Color.Green;

            }
        }

 
        else
            Imgemail.ImageUrl = "../NotAvailable.gif";
            lbl_msg.Text = "Not vaild email";
            lbl_msg.ForeColor = System.Drawing.Color.Red;
            Txtemail.Focus();       
    }

        else
        {
            lbl_msg.Text = "Please enter an email";
            lbl_msg.ForeColor = System.Drawing.Color.Red;
            Txtemail.Focus();
        }
    }
}
Answers (17)