Wednesday 22 August 2012

Cross Page Posting Example

 Cross Page Posting

I have scenario that I want to transfer control value one page to another on button click event. Most of developer can achieve this functionality using Server.Transfer Method which preserver the HttpContext of current page before transferring to other page, because HttpContext is preserved you can access the source page’s items collection in target hence called cross page posting.
This functionality comes at price, the basic problem is that this transfer occurs at server level and current page must post back to itself before it can transfer to other page results extra processing overhead.
Now new version we can achieve this functionality using following examples.
I have two controls on one “Webform1.aspx”. “TxtName” as Textbox Control  and “BtnRedirect” as BtnControl. On Click of BtnRedirect I want transfer text box value into other form.  As per following screen shot I want transfer 32 value into “WebForm2.aspx”.


WebFormat1.aspx
When user clicks the button the current page will post back to the specified page which can access the source page controls through Page.PreviousPage property which returns the reference of previous page, once got the reference of previous page you can use the Find Control method to get the reference of particular.


WebForm2.aspx
PreviousPageType directive specifies the virtual path of the source page for strongly typed access to the source page, but the problem with this approach is that you can only specify one previous page type and it cannot be used for pages which can be destination for multiple pages in this case only option left is late bind access using Find Control method or reflection.
In this “Webform.aspx”  I declared Label and transfer value assign to this label.


Step for SQL Profiler

 SQL Profiler 


·        Open Profiler we can write profiler in SQL 2008 and profiler90 in SQL 2005 in Run.
·        Create your connection to server using Ctrl + N. Below screen will come
o   You can connect server using SQL authentication or Window Authentication.

·    After connect  will display the ‘Trace Properties’ screen. On this screen you can enter the trace name. You will notice that trace provider name, type and versions are per-populated and cannot be altered. These are set based on which SQL Server instance you are connected with.

·    The ‘Trace Properties’ screen contains a drop-down for template selection, which is labeled with ‘Use the template’. As mentioned earlier, the default template selected is Tuning. We can see what events are included in the Tuning template in the next tab, ‘Events Selection’.

·    The ‘Event selection’ screen contains a check box that can be configured as per the requirement of data to be collected. The same screen contains a ‘Column Filters’ button, which when clicked brings up another screen that can be used to further filter trace data.

·    There is another button named ‘Organize Columns’ on the same screen. This screen can be used to organize and group columns. Please note that columns cannot be grouped or ordered once the process of trace collection has begun.
The ‘Trace Properties’ screen contains a ‘Run’ button. When you click on this button, it runs the trace. The trace can be paused or stopped as required using the play menu on top.\
·    This data can be saved in database and trace file or saved as XML. Trace file can be imported back in profiler, and profiler can re-run the whole scenario. Once the trace file is saved in database table, it can be queried by using T-SQL.