我有RadDatePicker控件和SelectedDateChanged事件。当我更改日期时,事件将通过“确认”窗口触发。当我点击'取消'按钮RadDatePicker1_SelectedDateChanged再次调用,它会两次显示确认窗口。当我点击' OK'按钮它工作正常。可能是什么问题呢?谢谢你的任何建议。
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" AutoPostBack="true" OnSelectedDateChanged="RadDatePicker1_SelectedDateChanged" >
</telerik:RadDatePicker>
protected void RadDatePicker1_SelectedDateChanged(object sender, EventArgs e)
{
string radalertscript = "<script language='javascript'>function f(){ radconfirm('Are you sure?', confirmChange, 400, 100) ; Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert33", radalertscript);
}
这是Javascript函数
function confirmChange(args) {
if (args) {
__doPostBack("<%= hiddenButton1.UniqueID %>", "");
}
答案 0 :(得分:1)
如果你只是用它来渲染一些javascript,这似乎是一个不必要的回发。
您可以在客户端进行确认对话吗?
http://www.telerik.com/help/aspnet-ajax/calendar-on-date-selecting.html
<script type="text/javascript">
function ConfirmChange(sender, eventArgs) {
var date = eventArgs.get_renderDay().get_date();
var dfi = sender.DateTimeFormatInfo;
var formattedDate = dfi.FormatDate(date, dfi.ShortDatePattern);
eventArgs.set_cancel(!confirm("Are you sure you want to " +
(eventArgs.get_isSelecting() ? "select " : "unselect ") +
formattedDate + "?"));
}
</script>
<telerik:RadCalendar ID="RadCalendar1" runat="server">
<ClientEvents OnDateSelecting="ConfirmChange" />
</telerik:RadCalendar>