【问题标题】:How to retrieve DynamicData DetailsView Viewstate when a SqlException occurs during Inserting?插入期间发生SqlException时如何检索DynamicData DetailsView Viewstate?
【发布时间】:2010-11-29 18:48:36
【问题描述】:

使用 DyanamicData,我有一个标准的多对多表,在插入新的唯一行时可以正常工作。两个父表的下拉列表都按原样显示,并且行被正确插入。

但是,在一张桌子上,我有一个唯一索引,它会引发一个异常,我可以在 OnInserted 事件处理程序中捕获该异常。然后,我可以向用户发回一条友好的消息,告知他们问题所在。出现此问题的原因是 DetailsView 丢失了视图状态,并且用户为 DropDownLists 选择的值被重置为页面的默认值。

protected void DetailsDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception != null && !e.ExceptionHandled)
    {
        msgPanel.Text = "Error Occurred"; // or some other friendly message
        e.ExceptionHandled = true;

        // e.Result == null, so I can't rebuild the user's input from here.
        // What can be put where to get the user's input restored?
    }
}

【问题讨论】:

  • 问题是不是不清楚,还是没有人对此有解决方案?我不可能是唯一遇到这个问题的人。

标签: linq-to-sql dynamic-data asp.net-dynamic-data


【解决方案1】:

我倾向于将错误包装在模型中的验证异常中,这会导致验证错误,并且应该使您的用户输入保持不变。

史蒂夫

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    相关资源
    最近更新 更多