Question: im very new to C# and ASP.Net. Does anybody know how to create a popup in Asp?

My scenario:

When I click on a button, it checks some states. If a condition is being fulfilled a popup shall be thrown due to the state (here: achieved percentages).

So 2 invidual Popup Windows shall be thrown by clicking the same button.

> 
> (Do you want to abort the contract, which wasn't completed? Yes - No)
> 
> 
> (Do you want to completed the contract, which hasn't achieved the target? Yes - No)
> 
> 
> 

So the dialog boxes shall appear according for the same button when the condition was fullfilled.

Can anybody help me? (Code behind in C# and javascript?)

Answer: 
Hmm. Well, first of all,this code is probably so heavily I/O bound that optimizing anything but disk access is probably inconsequential. You might try throwing a pointless loop to 1000 before every if-test just to see how much difference that makes.

It doesn't appear like indexing would help you here, since you must access all the data when a value isn't specified, but if you are computing aggregates then caching those might help. [Intersystem's DeepSee](http://docs.intersystems.com/cache20101/csp/docbook/DocBook.UI.Page.cls?KEY=SETDeepSee) product is designed for that.

But it sounds like maybe you are just running a big report printing all the data, and want to optimize what you can. In that case, I think your solution does that. As far as elegance, well, it usually isn't found in conjunction with heavy optimization. The problem with generalizing a solution is that it's usually slower than a tailored solution.

I think possibly using tags and goto statements, while much harder to read, might run a little faster than your solution - if you think it's worth it. The fact that Intersystems does tags and gotos in their compiled SQL routines makes me think it's likely the fastest option. I haven't measured the difference, but I suppose Intersystems probably has. If you really need speed then you should try different approaches and measure the speed. Be sure to test with warm and cold routine and global caches.

As far as a general solution, you could, if you really wanted to, write something that *generates* code similar to what you hand-coded, but can generate it for a general n level solution. You tell it about the levels and it generates the solution. That would be both general and fast - but I very much doubt that for this example it would be a good use of your time to write that general solution, since hand-coding is pretty trivial and most likely not that common.
You are going in right direction with your proposed answer, but I would change it slightly to avoid using xecute (xecute and performance rarely play well) and make overall architecture a bit better. 

Instead of deciding what to do in main routine and passing in only needed parameters, pass in all parameters and decide what you need to do in subroutine itself. 

So your code will become:

```
GatherData(...)
    set date=fromDate-1,status=""
    for {
        set status=$order(^GLOBAL(status)) quit:status=""
        for {
            set date=$order(^GLOBAL(status,date)) quit:((date>toDate)||(date=""))
            do LoopThroughRegions(status,date,state,region,street,.dataCollection)
        }
    }
 quit

LoopThroughRegions(status,date,state,region,street,dataCollection)
    if region'="" {
        do LoopThroughStreets(status,date,state,region,street,.dataCollection) 
        quit
    }
    set currentRegion="" 
    for {
        set currentRegion=$order(^GLOBAL(status,date,region,currentRegion)) quit:currentRegion=""
        do LoopThroughStreets(status,date,state,currentRegion,street,.dataCollection)
    }
 quit

LoopThroughStreets(status,date,state,region,street,dataCollection)
    if street'="" {
        do LoopThroughData(status,date,state,region,street,dataCollection) 
        quit
    }
    set currentStreet=""
    for{
        set currentStreet=$order(^GLOBAL(status,date,state,region,currentStreet)) quit:currentStreet=""
        do LoopThroughData(status,date,state,region,currentStreet,.dataCollection)
    }
 quit

LoopThroughData(status,date,state,region,street,dataCollection)
    set dataItem="" 
    for{
        set dataItem=$order(^GLOBAL(status,date,state,region,street,dataItem)) quit:dataItem=""
        // Do stuff
    }
 quit

```

I would also recommend to change these small subroutines to private procedures.