简体   繁体   English

DropDownList 事件不会触发

[英]DropDownList events don't fire

I'm having trouble with my DropDownList.我的 DropDownList 有问题。 The events don't fire!事件不会触发! I've tested it on a separate project, with a DropDownList and a literal.我已经在一个单独的项目上测试过它,有一个 DropDownList 和一个文字。 Every time the selected value would change, I would add a little star “*” to the literal.每次选定的值发生变化时,我都会在文字中添加一个小星“*”。 No problems what so ever.没有任何问题。 But every time I try it on my webpage in the project, it fails.但是每次我在项目中的网页上尝试时,它都失败了。

Here is an image.是一张图片。

protected void ddlConsole_SelectedIndexChanged(object sender, EventArgs e)
{
    ltlTesting.Text += "*";
}

UPDATE:更新:

I've tried some things but still with no succes.我尝试了一些东西,但仍然没有成功。 I hope someone can tell me what i'm doing wrong.我希望有人能告诉我我做错了什么。 I'm wiring the events in the code behind now, but i've added a linkbutton next to the dropdownlist to see if it works.我现在正在后面的代码中连接事件,但我在下拉列表旁边添加了一个链接按钮以查看它是否有效。

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ddlConsole.SelectedIndexChanged += new EventHandler(ddlConsole_SelectedIndexChanged);
        lnkGet.Click += new EventHandler(ddlConsole_SelectedIndexChanged);
    }

Here is an image to see what's going on.这是一张图片,看看发生了什么。 The stripe in the literal at the beginning is added in pageload with the same code the star is added.开头文字中的条纹添加到页面加载中,其代码与添加星号的代码相同。 Just to be sure it doesn't load twice.只是为了确保它不会加载两次。 The "GET" linkbutton works fine. “GET”链接按钮工作正常。 The dropdownlist doesn't...下拉列表不...

Have you Set你设置了吗

AutoPostBack="true"

in control properties??在控制属性中??

EDIT:编辑:

Remove消除

OnSelectedIndexChanged="ddlConsole_SelectedIndexChanged"

from the markup in the ASPX page and try again only with AutoPostback true and the event defined in codebehind.从 ASPX 页面中的标记并仅使用 AutoPostback true 和代码隐藏中定义的事件重试。 The aspx page should look like this: aspx 页面应如下所示:

 <asp:DropDownList runat="server" ID="ddlConsole" AutoPostBack="True"></asp:DropDownList>

下拉列表的AutoPostBacktrue吗?

检查 Dropdownlist 的 AutopostBack 属性将其设置为 true :

如果图片正确并且AutoPostBack="True" ,是否有任何代码在页面加载时设置ltlTesting的值?

Add the AutoPostback="True" and OnSelectedIndexChanged="ddlConsole_SelectedIndexChanged" to the ddlConsole attributes.AutoPostback="True"OnSelectedIndexChanged="ddlConsole_SelectedIndexChanged"到 ddlConsole 属性。 You can delete the OnInit method, since you bound the SeletedIndexChanged event at design time.您可以删除OnInit方法,因为您在设计时绑定了 SeletedIndexChanged 事件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM