0

can you help me with something i struggle for 4 days, button event doesn't fire :( In the MasterPage i use this to add control

 <Login:UserLogin runat="server" ID="UserLogin"  EnableViewState="false" > </Login:UserLogin>

and the control is this

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserLogin.ascx.cs" Inherits="BookApartmentsPortal.controls.UserLogin"  %>
    <%@ Register TagPrefix="MultiLanguage" Namespace="MultiLanguage.multilanguage" %>

<%--
<script type="text/javascript">        
       function DeleteKartItems() {  
                var inputEmail =   $("#ctl00_UserLogin_txtEmailVal").val();
                var user = {
                    email: "s.krastanov",
                    password: "1"
                };


              $.ajax({
               type: "POST",
               url: 'PublicDefault.aspx/Getvalues',
               data: JSON.stringify({ person: user }),
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: function (msg) {
                   $("#divResult").html("success");
               },
               error: function (e) {
                   $("#divResult").html("Something Wrong.");
               }
           });
           $("#ctl00_PublicDefault_buttonLog").Click();
   }
</script>--%>


    <h3>
        <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral13" runat="server" Resource="669" />
    </h3>
    <form action="/" method="POST" id="formasd">
        <div class="">
            <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral14" runat="server" Resource="858" />
            <%--user name input field--%>
            <input type="text"  class="modal-input" runat="server" size="20" id="txtEmailVal"
                name="txtEmail" />
            <%--  <asp:TextBox runat="server" CssClass="modal-input" ID="txtEmailVal" ></asp:TextBox> --%>
            <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral21" runat="server" Resource="205" />
            <%--password input field--%>
            <%--<input type="password" class="modal-input" runat="server" size="1" maxlength="20" id="txtPassword" />--%>
            <asp:TextBox runat="server" CssClass="modal-input" TextMode="Password" ID="txtPassword"
                MaxLength="20" CausesValidation="false"></asp:TextBox>
            <asp:Label ID="Label1" runat="server">
            </asp:Label>

    <asp:Panel ID="panelLogin" runat="server" DefaultButton="btnLogon">
            <asp:Button runat="server" ID="btnLogon" Text="Click" CssClass="login-btn" OnClick="btnLogon_Click"></asp:Button>
            </asp:Panel>
      <%--      <button class="login-btn" runat="server" id="btnLogon" name="btnLogon" onclick="DeleteKartItems()">
                <i class="fa fa-paper-plane"></i>
                <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral4" runat="server" Resource="1270" />
            </button>--%>

            <div id="divResult">
            </div>
        </div>
    </form>
    <asp:HyperLink ID="LoginFB" Target="_blank" runat="server" CssClass="btn btn-block btn-social btn-facebook fb-login">
        <i class="fa fa-facebook"></i>
        <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral27" runat="server" Resource="1306" /></asp:HyperLink>
    <a href="#lost-pass" class="button-modal various-login"><i class="fa fa-lock"></i>
        <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral22" runat="server" Resource="164" /></a>
    <a href="#reg" class="button-modal reg"><i class="fa fa-user"></i>
        <MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral23" runat="server" Resource="1271" /></a>

Backend is this:

    public partial class UserLogin : System.Web.UI.UserControl
    {



          protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack) 
            {

                this.btnLogon.Click += new System.EventHandler(btnLogon_Click);
                Response.Write("you click");
            }

            this.btnLogon.Click += new System.EventHandler(btnLogon_Click);

            LoginFB.NavigateUrl = "https://www.facebook.com/v2.0/dialog/oauth/?client_id=" + ConfigurationManager.AppSettings["FacebookAppId"] + "&redirect_uri=http://" + ConfigurationManager.AppSettings["URL"].ToString() + "/Publish/UserFB.aspx&response_type=code&state=1";

        }

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            //btnLogon.ServerClick += new EventHandler(btnLogon_Click);
            this.btnLogon.Click += new System.EventHandler(btnLogon_Click);
            //btnLogon.ServerClick += new CommandEventHandler(btnLogonClick);
           // btnLogon.Command += btnLogon_Click;
        }


        public void btnLogon_Click(object sender, EventArgs e)
        {
            Label1.Text = "submit button is press";
           // if (LoginSet == false )
           // {
                string Name = txtPassword.Text;
                string Dev = txtEmailVal.Value;

                String[] RemoteAddr = Request.ServerVariables.GetValues("REMOTE_ADDR");
                if (RemoteAddr.Length <= 0)
                    return;

                LoginDB oLoginDb = new LoginDB(txtEmailVal.Value.Trim(), txtPassword.Text.Trim(), true, RemoteAddr[0].ToString());
                oLoginDb.Database = new SQLDatabase(Convert.ToString(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString()));

                try
                {
                    if (oLoginDb.Authenticate(ConfigurationManager.AppSettings["SecKeyIni"].ToString(), ConfigurationManager.AppSettings["SecKeySec"].ToString()))
                    {
                        Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now;
                        FormsAuthentication.RedirectFromLoginPage(txtEmailVal.Value.Trim(), false);

                        Session["LoginUserName"] = txtEmailVal.Value.Trim();
                     //   _loginSet = true;

                    }
                    else
                    {
                     //   _loginSet = false;

                    }
                }
                catch (Exception Exception)
                {
                    Context.Trace.Warn(Exception.Message);
                    Global.ErrorMessage(Exception.Message, Context);
                 //   _loginSet = false;

                }

            //}
        }
}

This control is for login form and i just cant get the values from input boxes because event don't trigger. One idea was to make AJAX post to static method but after that i cant make new session with this variables. I try everything and this button just doesn't fire the event. I don't know what to do next, can you help me.

4
  • Is it executed without errors? I alwasy get " of type 'Button' must be placed inside a form tag with runat=server." because of missing runat attribute in your example Sep 10, 2015 at 12:00
  • Which button is the problem? Sep 10, 2015 at 12:15
  • if i put runat="server" on the form from the control ( <form action="/" method="POST" id="formasd" runat="server">) browser doesn't render anything Sep 10, 2015 at 12:19
  • the problem is: <asp:Button runat="server" ID="btnLogon" Text="Click" CssClass="login-btn" OnClick="btnLogon_Click"></asp:Button> Sep 10, 2015 at 12:19

1 Answer 1

0

Ok after one more day of struggle, i manage to make a little walk around path: In the first step i made a Button to fire event (javascript function) and make cookie, after that i make click event for actual asp:Button :

<script type="text/javascript">        
       function LoginClicked() {  
                var inputEmail =   $("#txtEmail").val();
                var inputPass =   $("#txtPassword").val();
                if(inputEmail != "" && inputPass != ""){

                var userSet = inputEmail + "&" + inputPass;
                setCookie("UserSettings", userSet, 1);

                function setCookie(cname, cvalue, exdays) {
                    var d = new Date();
                    d.setTime(d.getTime() + (exdays*1*60*1000));
                    var expires = "expires=" + d.toGMTString();
                    document.cookie = cname+"="+cvalue+"; "+expires;
                 }
          $("#ctl00_UserLogin_btnLogon").click();
           }
   }
</script>

And here is the buttons:

<asp:Panel runat="server" ID="panekl">
            <asp:Button runat="server" ID="btnLogon" UseSubmitBehavior="false" CssClass="no-display" ></asp:Button>
      </asp:Panel>
             <button class="login-btn" id="btnLogon1" name="btnLogon1" onclick="LoginClicked()">
             <i class="fa fa-paper-plane"></i><MultiLanguage:MultiLanguageLiteral ID="MultiLanguageLiteral4" runat="server" Resource="1270" />

And in the back end, i get the cookie, split it, and check for validation:

public void btnLogon_Click()
        {

           if (LoginSet == false )
           {
                string[] txtSome = Request.Cookies["UserSettings"].Value.Split('&');
                if (Request.Cookies["UserSettings"] != null && txtEmailVal != "" && txtPassword != "")
                {
                    txtEmailVal = txtSome[0].Trim();
                    txtPassword = txtSome[1].Trim();

                }

                String[] RemoteAddr = Request.ServerVariables.GetValues("REMOTE_ADDR");
                if (RemoteAddr.Length <= 0)
                    return;

                LoginDB oLoginDb = new LoginDB(txtEmailVal, txtPassword, true, RemoteAddr[0].ToString());
                oLoginDb.Database = new SQLDatabase(Convert.ToString(ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString()));

                try
                {
                    if (oLoginDb.Authenticate(ConfigurationManager.AppSettings["SecKeyIni"].ToString(), ConfigurationManager.AppSettings["SecKeySec"].ToString()))
                    {

                        Session["IdUserLogin"] = txtEmailVal;

                       _loginSet = true;
                       HttpCookie myCookie = new HttpCookie("UserSettings");
                       myCookie.Expires = DateTime.Now.AddDays(-1d);
                       Response.Cookies.Add(myCookie);
                       Label1.Text = "submit button is press";

                    }
                    else
                    {
                       _loginSet = false;

                    }
                }
                catch (Exception Exception)
                {
                    Context.Trace.Warn(Exception.Message);
                    Global.ErrorMessage(Exception.Message, Context);
                 _loginSet = false;

                }

           }
        }

This was the only way i figured out to get values from the control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.