简体   繁体   English

选定的索引更改事件未同时触发两个自动回发属性

[英]Selected Index Changed event not firing both Autopostback property

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 在我的下拉列表中,未触发选定索引更改事件。这里我使用自动回发true和查看状态也为true。但是选定索引更改事件未触发

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. ServerSide用户绑定到下拉列表正在工作。

   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);


 }
}

You shouldn't put a form element inside another form: 您不应该将表单元素放在另一个表单中:

<form accept-charset="UTF-8" role="form">
  <fieldset>
    ...
    <asp:Button ID="submit" runat="server" class="btn btn-lg btn-success btn-block" Text="Submit" OnClick="submit_Click" />
   </fieldset>
 </form>

remove the inner form. 删除内部形式。

[Update] [更新]

Another problem is the "ID" property of the button. 另一个问题是按钮的“ ID”属性。 change it to something else, other than "submit". 将其更改为“提交”以外的其他内容。

Try this: 尝试这个:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        BindUsers();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在事件处理程序之外的代码隐藏部分中,确定是否更改了所选索引或触发了自动回发事件 - Determine whether the selected index was changed or an autopostback event was triggered, in sections of the code-behind other than the event handler 在页面加载期间的数据绑定期间,未为DropDownList触发选定索引已更改事件 - Selected Index Changed event not firing for a DropDownList during databind at pageload 为什么列表框选择的索引更改不触发? - why listbox selected index changed is not firing? 组合框“所选文本已更改”事件未触发 - combobox Selected Text changed event not firing HTMLselect选定索引已更改事件 - Htmlselect selected index changed event DropDownList 事件未在 AutoPostBack 设置为 true 时触发 - DropDownList event not firing with AutoPostBack set to true 为什么附加属性属性更改事件只触发一次? - Why is attached property property changed event only firing one time? 调用dropdownlist选择索引已手动更改事件 - call dropdownlist selected index changed event manually 组合框选择的索引更改事件未在代码中触发 - Combobox selected index changed event not fired in code 如何仅在按下提交按钮时提交ASP.NET表单,而不是通过自动回发更改下拉列表的选定索引时才提交ASP.NET表单? - How to submit ASP.NET form only when the submit button is pressed and not when the selected index is changed of a dropdownlist with autopostback?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM