简体   繁体   English

在VB.Net中指示控件的保存顺序

[英]Dictating Save Order of Controls in VB.Net

I have a parent page that contains a placeholder. 我有一个包含占位符的父页面。 Span elements that contain IFrames are added to this placeholder as new IFrames are needed. 包含IFrame的跨度元素会添加到此占位符,因为需要新的IFrame。 Each IFrame contains an asp control. 每个IFrame都包含一个ASP控件。 The parent has this code, fired onClick of the parent page: 父级具有以下代码,在父页面的onClick上触发:

function saveAll() {

        for (i = 0; i < frames.length; i++) {
            for (j = 0; j < frames[i].length; j++) {
                if(frames[i][j] != null && frames[i][j] != ''){document.getElementById(frames[i][j].toString()).contentWindow.Save();}
            }
        }
    }

which calls a save function within each control, which in turn, fires a button click, which fires the server side save function for that specific control. 会在每个控件中调用保存功能,从而触发按钮单击,从而触发该特定控件的服务器端保存功能。 To someone trying to read this in 30 seconds...the previous sentence might be found to be confusing...so hopefully this might clarify the big picture here: 对于试图在30秒内阅读此内容的人...可能发现前一句令人困惑...因此希望可以澄清这里的大局:

在此处输入图片说明

The problem I'm having is that the server is processing the controls out of order, despite the frames being ordered. 我遇到的问题是,尽管帧已排序,但服务器仍在无序处理控件。

the frames object in the aforementioned javascript is a 2D array organized like this: 上述javascript中的frame对象是一个2D数组,其组织方式如下:

frames 镜框
[[controlA_instanceA,controlA_instanceB,controlA_instanceC], [[controlA_instanceA,controlA_instanceB,controlA_instanceC],
[controlB_instanceA,controlB_instanceB], [controlB_instanceA,controlB_instanceB],
[controlC_instanceA,controlC_instanceB,etc], [controlC_instanceA,controlC_instanceB等],
[etc]] [等等]]

The loop, the firing of the child controls, and the frames array is all working correctly (hence why I didn't show the code here). 循环,子控件的触发以及frames数组都正常工作(因此,为什么我在这里没有显示代码)。 However, could someone point me in the right direction on how to enforce the order the server processes the controls in? 但是,有人可以向我指出如何执行服务器处理控件的顺序的正确方向吗?

Your controls need a sequence number assigned to them. 您的控件需要分配一个序列号。 Then the first step of your save all would be to decompose the 2D array into a 1D array organized by the sequence number. 然后,保存所有内容的第一步将是将2D数组分解为由序列号组成的1D数组。

When you are adding an item to the frames array you need to add them as an object with two members: 将项目添加到框架数组时,需要将它们添加为具有两个成员的对象:

var seqNo = 0; // at some point early in the script

...

frames[x][y] = {frame: (iFrame), sequence: seqNo}; //When the Control is added
seqNo++;

where (iFrame) is the id of the frame. 其中(iFrame)是框架的ID。

Then your save all function would look like this: 然后,您的全部保存功能将如下所示:

function saveAll() {

    var iFrames = [];

    for (i = 0; i < frames.length; i++) 
    {
        for (j = 0; j < frames[i].length; j++) {
            if(frames[i][j] != null && frames[i][j] != '')
            {
                iFrames.push(frames[i][j]);
            }
        }
    }

    iFrames.sort(function(a,b){ return a.sequence - b.sequence});

    for ( t = 0; t < iFrames.length; t++)
    {
        document.getElementById(iFrames[t].frame.toString()).contentWindow.Save();
    }
}

In this way you are ensuring that the order is preserved because you sorted the array by the sequence number. 这样,您可以确保保留顺序,因为您已按序列号对数组进行了排序。

This is to say that the problem could be that the array appears to be sorted but it is not and and not assuming the issue is the order in which the server is responding to the click events. 就是说,问题可能在于数组似乎已排序,但不是,并且也未假设问题是服务器响应单击事件的顺序。

EDIT: 编辑:

If the server is responding to the events out of order then you may need a different approach. 如果服务器对事件的响应不正常,则可能需要其他方法。

If this is an ajax site and you are posting back via a web method then I would suggest creating a new web method that takes an array as a parameter. 如果这是一个Ajax网站,并且您要通过Web方法回发,那么我建议创建一个新的Web方法,该方法将数组作为参数。

Push all the content you wish to save into the array and then pass it back to the server for processing in a specific order. 将所有要保存的内容推入数组,然后将其传递回服务器以特定顺序进行处理。

If this is a classic forms site then you can handle a custom postback in your page load event. 如果这是经典表单网站,则可以在页面加载事件中处理自定义回发。

Either way it sounds like you need to re-evaluate the way this is processing. 无论哪种方式,听起来您都需要重新评估其处理方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM