简体   繁体   English

Asp.NET用户控件回发问题

[英]Asp.NET User Control Postback Issue

I have a aspx page that has a Tab control, a few buttons and a User Control on it. 我有一个aspx页面,上面有一个Tab控件,一些按钮和一个用户控件。

<dx:TabPage Text="Worker Information" Name="tabWorker">
    <ContentCollection>
        <dx:ContentControl runat="server" SupportsDisabledAttribute="True">
            <uc:WorkerInfo runat="server" OnWorkerLoaded="On_Worker_Loaded" OnWorkerUnloaded="On_Worker_Unloaded" />
        </dx:ContentControl>
    </ContentCollection>
</dx:TabPage>

There are 2 custom events on the user control 用户控件上有2个自定义事件

public event EventHandler WorkerLoaded;
public event EventHandler WorkerUnloaded;

I have the event handlers in the main aspx page 我在aspx主页上有事件处理程序

protected void On_Worker_Loaded(object sender, EventArgs e)
{
    btnNext.Enabled = true;
}

protected void On_Worker_Unloaded(object sender, EventArgs e)
{
    btnNext.Enabled = false;
}

The On_Worker_Loaded event fires without an issue. 触发On_Worker_Loaded事件没有问题。 I can debug and watch the button become enabled. 我可以调试并观察按钮变为启用状态。 My problem is when the screen loads the button is still disabled. 我的问题是,在屏幕加载时,按钮仍处于禁用状态。 In my aspx page I disable the button: 在我的aspx页面中,我禁用了按钮:

<dx:ASPxButton ID="btnNext" runat="server" Text="Next" Theme="MetropolisBlue" 
                onclick="btnNext_Click" Enabled="false"></dx:ASPxButton>

在此处输入图片说明 The 'Next' button is already disabled. “下一步”按钮已被禁用。 This is why you can't really see it. 这就是为什么您看不到它的原因。 I have framed it with the black outline. 我已经用黑色轮廓框住了。 When I click that OK button the WorkerLoaded Event fires. 当我单击该“确定”按钮时,将触发WorkerLoaded事件。

The only other disable is on the On_Worker_Unloaded Event Handler. 唯一的其他禁用是在On_Worker_Unloaded事件处理程序上。 I don't have it hooked up yet. 我还没有连接。 There is nothing else that causes the button to disable. 没有其他原因导致按钮禁用。 Any Ideas what I'm missing? 有什么想法我想念的吗?

Thanks! 谢谢!

UPDATE UPDATE

The User Control has a UpdatePanel in it. 用户控件中有一个UpdatePanel。 I don't know if that makes a difference but I thought I would include that. 我不知道这有什么不同,但我想我会包括在内。 Something else weird happened I noticed. 我注意到发生了一些奇怪的事情。 After enabling the button I noticed that if I did a postback the button would be enabled. 启用按钮后,我注意到如果执行回发,则将启用该按钮。 Does that ring any bells for anyone? 这会给任何人敲响钟声吗?

It seems the loaded event is being called before the Enabled=false property is set. 似乎在设置Enabled = false属性之前就调用了已加载的事件。

In your debugger check to see whether the Enabled property is already false when the event is called. 在调试器中,检查调用事件时Enabled属性是否已经为false。

Also, what triggers the WorkerLoaded event? 另外,什么触发了WorkerLoaded事件?

In the end I found a solution that works for me. 最后,我找到了适合我的解决方案。 I put the Next button and the Previous buttons inside their own Update Panel. 我将“下一个”按钮和“上一个”按钮放在自己的“更新面板”中。 After I did this everything worked without issue. 完成此操作后,一切正常。 Thanks for all the ideas and help. 感谢您的所有想法和帮助。

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

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