Selected Index Changed event not firing both Autopostback property

Posted by TechGuy on Stack Overflow See other posts from Stack Overflow or by TechGuy
Published on 2014-05-31T07:06:07Z Indexed on 2014/05/31 9:26 UTC
Read the original article Hit count: 222

Filed under:
|
|

In my Dropdownlist Selected index change event not firing.Here i use auto post back true & View state also true.But Selected Index Changed Event not firing

My Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdminEagleViewLogin.aspx.cs" Inherits="AdminEagleViewLogin" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style>
        body{padding-top:20px;}
    </style>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
    <div class="row">
          User :  <asp:DropDownList ID="drpusr" runat="server"  Visible="true" OnSelectedIndexChanged="drpusr_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true" ></asp:DropDownList>
       Password: <asp:Label ID="lbluserpw" runat="server"></asp:Label>
        <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Please sign in</h3>
                </div>
                <div class="panel-body">
                    <form accept-charset="UTF-8" role="form">
                    <fieldset>
                        <div class="form-group">
                           <asp:TextBox ID="txtusr" runat="server"></asp:TextBox>
                        </div>
                        <div class="form-group">
                             <asp:TextBox ID="txtpw" runat="server" TextMode="Password"></asp:TextBox>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input name="remember" type="checkbox" value="Remember Me"> Remember Me
                            </label>
                        </div>
                     <asp:CheckBox ID="chkremember" runat="server" Visible="false" class="remchkbox" />
                         <asp:Button ID="submit" runat="server" class="btn btn-lg btn-success btn-block" Text="Submit" OnClick="submit_Click" />
                    </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
    </form>
</body>
</html>

ServerSide User bind to Dropdown is working.

   public partial class AdminEagleViewLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindUsers();
        //lbluserpw.Text = Membership.Provider.GetPassword(drpusr.SelectedValue, String.Empty);
    }
    protected void submit_Click(object sender, EventArgs e)
    {

        if (Membership.ValidateUser(txtusr.Text, txtpw.Text))
        {
            FormsAuthentication.SetAuthCookie(txtusr.Text, chkremember.Checked);
            string[] CurrentUserRole = Roles.GetRolesForUser(txtusr.Text);

            var admin = "Administrator";
            var manager = "Manager";
            var user = "User";

            if (CurrentUserRole.Contains(admin))
            {
                Response.Redirect("Administrator.aspx");
            }
            else if (CurrentUserRole.Contains(manager))
            {
                Response.Redirect("Manager.aspx");
            }
            else
            {
                Response.Redirect("UserPage.aspx");
            }
        }
        else
        {
            Response.Redirect("AdminEagleViewLogin.aspx");

        }
    }

    protected void BindUsers()
    {
        DataAccess da = new DataAccess();
        drpusr.DataSource = da.GetUsers();
        drpusr.DataTextField = "UserName";
        drpusr.DataValueField = "UserId";
        drpusr.DataBind();

        drpusr.Items.Insert(0, new ListItem("-- Select User --", "0"));
        drpusr.Items.RemoveAt(1);

    }

    protected void drpusr_SelectedIndexChanged(object sender, EventArgs e)
    {
       lbluserpw.Text = Membership.Provider.GetPassword(drpusr.SelectedValue, String.Empty);


 }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET