3rd party Slimee DatePicker:如何处理解析错误?

发布于 2024-11-17 15:59:07 字数 98 浏览 0 评论 0原文

我需要使用提到的第三方日期选择器,当输入无效日期时它会引发异常。作者仅公开一个事件,该事件在成功解析时触发。在 ASP.NET 中,我如何捕获此错误并采取措施(例如设置标签的文本)?

I need to use the mentioned 3rd party datepicker and it throws an exception when an invalid date it entered. The author only exposes one event, which is fired when a successful parse takes place. How, in ASP.NET could I catch this error and do something about it, like set a label's text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-11-24 15:59:07

您可以在此处采用多种方法,就我个人而言,我会通过继承替换 TextChanged 事件的默认事件处理程序。

代码在设置过程中分配了一个via,不幸的是文本框是一个私有成员

textBox.TextChanged += new EventHandler(OnSelectedDateChanged);  

,声明为

protected virtual void OnSelectedDateChanged(object sender, EventArgs e)

因此我们可以继承SlimeeLibrary.DatePicker

public class EnhancedDatePicker : SlimeeLibrary.DatePicker

,然后重写EventHandler,引发一个新的解析错误事件。

公共事件 EventHandler OnDateParseError;

protected override void OnSelectedDateChanged(object sender, EventArgs e)
{
    try
    {
        base.OnSelectedDateChanged(sender, e);
    }
    catch (FormatException fe)
    {            
        OnDateParseError(sender, e);
    }

}

希望有帮助。我还没有检查它,但已经检查了史莱姆控制的代码,但抱歉不想设置代码项目帐户来下载它。显然,您需要更改 ASP.NET 用户控件引用才能使用新类。

There are a couple of approaches you can take here, personally I would replace the default event handler for the TextChanged event via inheritance.

The code assigns one via during the setup and unfortunately textbox is a private member

textBox.TextChanged += new EventHandler(OnSelectedDateChanged);  

which is declared as

protected virtual void OnSelectedDateChanged(object sender, EventArgs e)

So we can inherit SlimeeLibrary.DatePicker

public class EnhancedDatePicker : SlimeeLibrary.DatePicker

and then override the EventHandler raising a new parse error event.

public event EventHandler OnDateParseError;

protected override void OnSelectedDateChanged(object sender, EventArgs e)
{
    try
    {
        base.OnSelectedDateChanged(sender, e);
    }
    catch (FormatException fe)
    {            
        OnDateParseError(sender, e);
    }

}

Hope that helps. I haven't checked it but have examined the code for slimees control, but don't want to setup a code project account to download it sorry. You'll obviously need to change your ASP.NET usercontrol references to use the new class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文