当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Is it possible (or something similar) to disable a button control from a calendar control when the selection is changed on the client side?

问题描述:

I'm not sure if this is possible but I'm looking for a solution that would give a similar effect. I have a calendar control on an asp.net (C#) page along with a button.

Here is some background as to how the page works: When the user selects a date range, there is a post back that shows data and also populates a few drop down boxes with data relevant to the selected date ranges. The dropdown boxes are used to filter the data, for example, the user could choose a specific customer to view data for. After the user selects filters from the drop down boxes, they would click the button to update the page with the filtered data. Alternatively, if they did not select a date and the button is clicked, the selected date range is assumed to be this week. The button is needed because we would prefer not to do multiple database calls if the user wants to use more than one filter from the dropdowns.

With that said, I want to be able to prevent each of these controls from calling another post back if there is already one in progress for the other control. I've seen disabling a button by doing this:

 <asp:Button ID = "ShowDataButton" runat="server"

OnClientClick="this.disabled = true;"

UseSubmitBehavior = "false"

onclick="ShowDataButton_Click"

Text = "Show Data"/>

Is there a similar property for a Calendar control that would allow me to disable the button control? Something like, OnClientSelectionChanged = "ShowDataButton.disabled = true;" From what I've researched so far, I'm not too hopeful that this exists. If it doesn't, is there another way that I could accomplish something similar? When I try to add ShowDataButton.Enabled = false; to the OnSelectionChanged event method in the code behind, the button doesn't get disabled until after the postback is finished, which I should have expected. Without something like this occurring, the calendar control ends up returning DateTime.MinValue if the user selects a date and then immediately clicks the button (as the post back takes a few seconds to complete). Any ideas or suggestions would be greatly appreciated.

网友答案:

Your OnClientClick property should actually call a javascript client-side, and then in the javascript you would need to do any actions you desire (eg disable a button, change its style to hide it, etc)

分享给朋友:
您可能感兴趣的文章:
随机阅读: