how to store a varibale value after page loading - asp.net

In my application there is the multiple tab concept is there. i.e i have 1st page then "next button" to move to second page, then in 2nd page 2 button(prev,next). Thus when user click prev button i need to get the fields filled in 1st page. this can be achived using state management. If is there any way except this?

You can use sessions, example of which
in your 1st page:
string str;
Session["someName"] = str;
in your 2nd page you can retrieve by calling the session, because sessoin is a GLOBAL VARIABLE,
string n_str;
n_str = Session["someName"] as string;

I think it all depends on how your project is built, so you've many options:
1- You could build it as a single page with multiple tabs (as HTML Divs) and the "next" and "prev" buttons show and hide these Divs, so you don't need to store the data anywhere as the page didn't change (just show and hide).
2- Store it in a global variable like "Session"
but if you've a high traffic application you may run out of memory or you'll need to use in database session instead of the default in memory session storage.
3- Save the data partially (when moving from step to step) by using a web service or from code behind to the database and then reload it again when clicking prev.
As for me I recommend the first approach as it doesn't add extra load on the servers and don't affect the performance.

Related

Call child form programmatically with parameter / filter

I'm creating a customization where on a click of a button, I need to allocate a charge for a particular purchase order / invoice journal.
From the front end, I would accomplish this by following the purchase order life-cycle and invoicing it. I would then go under the invoice tab of the PO, click Invoice Journals -> Charges -> Adjustment . This will open up my desired form where I will select a charges code, charges value, currency and category, and then I will click 'Ok' and have the system take care of the rest of the process.
Form name: MarkupAllocation_VendInvoiceTrans
Parent form Name: VendInvoiceJournal
You can see that the child form gets called with a few parameters such as the invoice number, there obviously needs to be that link. If I go into the AOT under forms, I right click and open up VendInvoiceJournal, but I wouldn't be able to open up MarkupAllocation_VendInvoiceTrans because it requires parameters.
Objective:
A: To open MarkupAllocation_VendInvoiceTrans through code where I manually pass those parameters to link to the parent table. I would provide the invoice number and such. The objective is to skip opening the parent table and manually going into the adjustments. I want to open that form directly and have it link to whichever record I specify.
B: I need to be able to pass a _ChargesValue parameter and have that be pre-populated for me. I don't know if this is possible, so I wanted to ask and confer. Ideally, I should be able to click a button on my custom form, and have MarkupAllocation_VendInvoiceTrans form directly open for a specified invoice, with pre-populated values on the line.
I know I should be tackling this problem one step at a time, so step A is priority number one.
I can open up the parent form with relative ease like so, but I cannot do the same for the child form. Obviously the same time of approach won't work, as I need to specify the relationship of the parent table before I open it.
private void allocateMarkup()
{
Object formRun;
Args args = new Args();
VendInvoiceJour jourTable;
;
select * from jourTable where jourTable.PurchId == 'PO000001191';
args.name(formstr(VendInvoiceJournal));
args.record(jourTable);
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
How would I be able to do so?
(Side note, I realize this whole form calling could be avoided if do all the transactions programmatically instead of letting the out of the box functionality handle it, but the markup and allocation logic is a beast of it's own and to me seems much more complicated than doing this. If someone has done it this manual way, any help on that would be greatly appreciated as well)
If I read your post right, you just want to open the Charges>Adjustment for a certain invoice. Here is one simple method:
MarkupAdjustment markupAdjustment = new MarkupAdjustment();
markupAdjustment.vendInvoiceJour(VendInvoiceJour::findFromPurchId('PO 120079'));
markupAdjustment.run();

copy/paste of Page doesn't start workflow in same SG, starts workflow in other SG

I was perplexed by a user turning up this sort of behavior recently. Assume all SGs have workflow set.
Copy Page X in SG A, paste in same SG A. Page Y is created but no workflow is initiated.
Copy Page X in SG A, paste in other SG B. Page Z is created and workflow is initiated.
Now, the first scenario I confirmed with Nuno when he was on site. We agreed with business folks that we can live with that behavior. However, I'm curious why the second scenario happens as-is. If #1 doesn't kick off workflow, why should #2? Can anyone explain why? Is there any way I could programmatically cause scenario #1 to start the workflow (as the business would like that to happen)? or, worst case disable it from #2. It should be consistent.
But in practical scenario, I would really question the need for workflow to kick off as soon as you copy the page in the same structure group.
When you copy a page in the same structure group, it will create a page with title Copy of original page name and the CMS User will obviously wants/needs to edit the page with proper page name. As soon as they save the page workflow kicks in. Also, CMS user may want to change some component presentations on the page as well.
When you copy this on a different structure group, you are creating a page with a name in other structure group, so the workflow kicks in since it is not same copy in same structure group.
I would consider this as a nice feature :) :).
However as Nick suggested I would recommend submitting a support ticket as well.
If you want to consider a programmatic approach for your scenario # 1, you could implement the EventSystem to force the workflow kick off by simply saving the page again with same user who created it. You need to capture the CopyEvent .
Sample EventSystem stub if you want to go this route (Not Tested) :
private void Subscribe()
{
EventSystem.Subscribe<Page, CopyEventArgs>(PostCopyActivity, EventPhases.Processed);
}
private static void PostCopyActivity(Page page, CopyEventArgs args, EventPhases phase)
{
// do your logic to save page..
string sourceId = args.CopiedObject.OrganizationalItem.Id;
string destinationId = args.Destination.ToString();
if (sourceId.Equals(destinationId))
{
// copying to the same location .. so now get the User Session and Update the page to force workflow
}
}
Hope this information helps.
I went ahead and tried this on my system, and it does not start a workflow in any case (copy/pasting to same structure group or different structure group).
Do you have an event triggered on Paste?

Variable number of reads from database before write clears data

I have a desktop vb6 application that is loading into a webbrowser control an asp.net webpage generated at a remote website.
On this webpage are a label and a button.
The label is filled with text from an Access database on the website.
In the asp.net page_load procedure there is a function (in a loop) that returns the data from the database and while the value returned is an empty string the loop repeats.
So there will be a timeout about every 2 minutes if there is no data.
Since the calling of the webpage by the vb6 app is itself inside a loop the webpage then gets called again
If there is data then the page_load completes.
Then the vb6 app clicks the button.
The server side code in the button's click eventhandler then edits the relevant database entry to an empty string.
This should mean that the vb6 app should not get the same data on the next call but what's happening is that the data might be sent 1,2,3,4.. times on successive calls before the data is cleared in the database.
I put in a delay of 0.5 second in the vb6 app after the button click and then everything worked as it should.
Can someone please explain why this happens?
"More details are required like code sample, you should also mention the problem which you are trying to resolve by this technique, you might get good suggestions.
"it could be that your VB6 loop loads the page before your last web request gets completed. – bjan
This was it, I wasn't waiting for the document to be completed.

Asynchronous validation in QWizard

I'm writing a wizard UI based on the QWizard Qt object. There's one particular situation where I want the user to log in to a service using host, username, and password. The rest of the wizard then manipulates this service to do various setup tasks. The login may take a while, especially in error cases where the DNS name takes a long time to resolve -- or perhaps it may not even resolve at all.
So my idea is to make all three fields mandatory using the registerField mechanism, and when the user hits Next, we show a little throbber on the wizard page saying "Connecting to server, please wait..." while we try to connect in the background. If the connection succeeds, we advance to the next page. If not, we highlight the offending field and ask the user to try again.
However, I'm at a loss for how to accomplish this. The options I've thought of:
1) Override validatePage and have it start a thread in the background. Enter a wait inside validatePage() that pumps the Qt event loop until the thread finishes. You'd think this was the ugliest solution, but...
2) Hide the real Next button and add a custom Next button that, when clicked, dispatches my long running function in a thread and waits for a 'validation complete' signal to be raised by something. When that happens, we manually call QWizard::next() (and we completely bypass the real validation logic from validatePage and friends.) This is even uglier, but moves the ugliness to a different level that may make development easier.
Surely there's a better way?
It's not as visually appealing, but you could add a connecting page, and move to that page. If the connection succeeds, call next() on the wizard, and if the connection fails, call previous() and highlight the appropriate fields. It has the advantage of being relatively straightforward to code.
My final choice was #2 (override the Next button, simulate its behavior, but capture its click events manually and do the things I want to with it.) Writing the glue to define the Next button's behavior was minimal, and I was able to subclass QWizardPage with a number of hooks that let me run my task ON the same page, instead of having to switch to an interstitial page and worry about whether to go forwards or backwards. Thanks Caleb for your answer though.
I know this has already been answered (a long time ago!) but in case anyone else is having the same challenge. Another method for this is to create a QLineEdit, initiate it as empty and set it as a mandatory registered field. This will mean that "Next" is not enabled until it is filled with some text.
Run your connection task as normal and when it completes use setText to update the QLineEdit to "True" or "Logged in" or anything other than empty. This will then mean the built in isComplete function will be passed as this previously missing mandatory field is now complete. If you never add it to the layout then it won't be seen and the user won't be able to interact with it.
As an example ...
self.validated_field = QLineEdit("")
self.registerField('validated*', self.validated_field)
and then when your login process completes successfully
self.validated_field.setText("True")
This should do it and is very lightweight. Be sure though that you consider the scenario where a user then goes back to that page and whether you need to reset the field to blank. If that's the case then just add in the initialisePage() function to set it back to blank
self.validated_field.setText("")
Thinking about it you could also add the line edit to the display and disable it so that a user cannot update it and then give it a meaningful completion message to act as a status update...
self.validated_field = QLineEdit("")
self.validated_field.setDisabled(True)
self.validated_field.setStyleSheet("border:0;background-color:none")
self.main_layout.addWidget(self.validated_field)
self.registerField('validated*', self.validated_field)
and then when you update it..
self.validated_field.setText("Logged in")

Caching strategy for asp.net

I would like to ask is there any way to achieve this functionality:
I have an Ajax enabled user web site (tree view on the left side, and content on the right side). When users selects a node on the left side, I need to store the last selected node in database. However the user can change the node quite often (even 5 or 10 times a minute).
So I would like to add it to the application cache, like:
cache["userName"]=selectedNodeID;
Is there any caching framework that would: perform certain action on a cache item if it wasn't changed for let's say 5 minutes? It would allow me to store last selected node id after 5 minutes from last change. If the user changes the node before this time passes - I would just update cache value and reset timer.
Any hints?
You could use the callback mechanism for when the cache item is removed from the cache. If you set the cache duration to 5 minutes, then you could check in your callback method whether the item has already been saved - if it hasn't then you can push it to the database. In either case, you can put the item straight back in the cache for another 5 minutes.
e.g. you would have something like this as the last parameter of your Cache.Insert method:
new CacheItemRemovedCallback (SaveItemToDatabaseAndReturnItToTheCache)
and then you would implement the callback method accordingly.
more info here: http://weblogs.asp.net/kwarren/archive/2004/05/20/136129.aspx

Resources