页面循环 - 将数据输入数据库的正确方法

发布于 2024-09-15 06:52:31 字数 266 浏览 1 评论 0原文

我有一个页面,有几个文本框和一个下拉列表。 当登录用户打开此页面时,框中将填充他之前输入的数据,他可以更改数据并通过按更新按钮进行更新。 还有一个下拉列表,其中有动态填充的数据供他选择。

使该页面正常工作的最佳方法是什么?我在页面周期的哪​​里填充表单以及在哪里将数据输入到数据表。

目前,我正在 PreRender 上填充数据,但在 preinit 上填充下拉列表。我有一个按钮事件处理程序来更新数据表。问题是自动回发弄乱了下拉列表中的数据,因为它是动态填充的,我该如何解决这个问题?

I have a page that has a few textboxes and a dropdownlist.
When a logged in user opens this page the boxes are filled with data that he has input before, he can change the data and update it by pushing a update button.
There is also that dropdownlist which has a dynamically populated data for him to choose from.

What is the best way to make this page work. Where in the page cycles do I populate the forms and where do I input the data to the datatable.

At the moment I'm populating the data on PreRender but the dropdownlist on the preinit. I have a button event handler to do the update on the datatable. The problem is that the autopostback messes up the data in the dropdownlist because its dynamically populated, how would I go by fixing this?

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

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

发布评论

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

评论(1

她比我温柔 2024-09-22 06:52:31

这是我在大多数情况下遵循的

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        InitDropdDownListes();
        LoadDataFromDataBase();
    }

}

void InitDropdDownListes()
{
    // fill drop down boxes

}

void LoadDataFromDataBase()
{
    // load from database

}

protected void OnDropdownListChanges(object sender, EventArgs e)
{
    // reload the new data from database
    LoadDataFromDataBase();
}


protected void btnSave_Click(object sender, EventArgs e)
{
    // Save to database

}

Here is what I follow in most of my cases

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        InitDropdDownListes();
        LoadDataFromDataBase();
    }

}

void InitDropdDownListes()
{
    // fill drop down boxes

}

void LoadDataFromDataBase()
{
    // load from database

}

protected void OnDropdownListChanges(object sender, EventArgs e)
{
    // reload the new data from database
    LoadDataFromDataBase();
}


protected void btnSave_Click(object sender, EventArgs e)
{
    // Save to database

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