在用户控件上进行运行时UI更改的最佳方法是什么?

时间:2013-08-22 05:30:34

标签: c# asp.net architecture user-controls code-design

我是.net的新手,我正在研究办公室的一些功能,如下所示

Jobs.aspx.cs

protected void gvActionItems_RowEditing(object sender, GridViewEditEventArgs e)
{
    //setting the value of the user control property 
}

JobUserControl.ascx.cs

public int _usrcontrolproperty
{
  get{return _usrcontrolproperty;}
  set{
    //depending on the value of the property fetch the data from the database and binding those data on the user controls FormView
    }
}

protected void fvJob_DataBound(object sender, EventArgs e)
{
   //Making the dynamic UI changes that is setting properties of controls  depending upon the values of binding data
}

这就是我在表单视图的数据绑定事件中所做的UI更改的方法,但是高级之一说'这是糟糕的架构代码设计它有额外的内存问题并且在_usrcontrolproperty set方法之后进行UI更改数据绑定。'。所以我想知道

1) Is this really bad architectural code ? If bad then why ?
2) And if my seniors way is bad then also Why ? 

因为我认为UI更改应该在绑定数据时完成

2 个答案:

答案 0 :(得分:1)

如果你的大四学生不能支持他/她的说法..那么他/她就不是你应该尝试学习的人。我不确定他/她所指的“内存问题”是什么,但很难用你的精简代码来判断。

话虽这么说,我会重新考虑一个属性集中的数据绑定,纯粹是因为当人们开始设置这个属性时,你会在轨道上打开自己的“陷阱”。

相反,我会使用Refresh()方法。因此,调用代码将是:

UserControl.Property = value;
UserControl.RefreshData();

这使得调用API可以选择在此时刷新或推迟决定。

答案 1 :(得分:0)

我和@Simon一起使用这个,但我会有一个RefreshData(value)方法。因此,调用代码将是:

UserControl.RefreshData(value);

这使得调用API可以选择在此时刷新或推迟决策。 在此方法中,您可以使用as,

 Public static RefreshData(<datatype>data)
 {
   //Assign the value to the property 
   //Get the data from database 
   //Bind the data 
 }

如果您不想将该属性公开给其他类,您也可以将您的属性设为私有或受保护。

相关问题