Ticket Q306498
Visible to All Users

How to add a hyperlink to a new object to a standard aspx page

created 14 years ago

Hi,
I have a XAF Application and then another standard ASP.NET application in which there are some pages. I wanna put in this app an HyperLink to let the user click and go directly (for example with a popup form) to a XAF detail view for a specified object type (Like the detail view for the New Action). Then, the user can put field into xaf application detail view, click save and close the popup form, returning to the other ASP.NET application.
In the picture, you can see that I want to get the link to a page that shows the "Appalti" detail view (WITHOUT left menu) in which the user can put informations.
How can I do this? There is a standard link?
Thanks, Paolo

Answers

created 14 years ago (modified 2 years ago)

Hello Paolo,

You can get a link to a DetailView with a certain object using a ViewShortcut. For example:

C#
Session session = new Session(); session.ConnectionString = "Integrated Security=SSPI;Pooling=false;Data Source=(local);Initial Catalog=Solution1"; ViewShortcut shortcut = new ViewShortcut("DomainObject1_DetailView", session.FindObject<DomainObject1>(null).Oid); string url = xafApplicationUrl + "?Shortcut" + shortcut.ToString();

To show a DetailView with a new object, handle the XafApplication.CustomProcessShortcut event (e.g. in the YourSolutionName.Web/Global.asax.xx file or from your Controller where you have access to its "Application" property) or override the protected virtual OnCustomProcessShortcut method of your XafApplication descendant in the YourSolutionName.Web/WebApplication.cs file, as shown below:

C#
ViewShortcut result = new ViewShortcut("DomainObject1_DetailView", null); result["mode"] = "ExternalCall"; HttpContext.Current.Response.Redirect(new DefaultHttpRequestManager().GetQueryString(result)); ... protected override void OnCustomProcessShortcut(DevExpress.ExpressApp.CustomProcessShortcutEventArgs args) { base.OnCustomProcessShortcut(args); if (args.Shortcut["mode"] == "ExternalCall") { args.Handled = true; IObjectSpace os = CreateObjectSpace(); IModelDetailView viewModel = (IModelDetailView)FindModelView(args.Shortcut.ViewId); object obj = os.CreateObject(viewModel.ModelClass.TypeInfo.Type); DetailView view = CreateDetailView(os, args.Shortcut[ViewShortcut.ViewIdParamName], true, obj); view.ViewEditMode = ViewEditMode.Edit; args.View = view; } }

If you are using the Security System with the Standard Authentication, you may also need to automatically login the user and skip the logon window. See how to do this here: How to skip the logon page and automatically authenticate a user in code (e.g. from an external link).
To show a DetailView without logging in the user, use the following solution: How to produce a web link that shows a DetailView of a certain object without authentication.

Update:
To show a DetailView with a new object, handle the XafApplication.CustomProcessShortcut event or override the XafApplication.OnCustomProcessShortcut method, as shown below:

Code
C#ViewShortcut result = new ViewShortcut("DomainObject1_DetailView", null); result["mode"] = "ExternalCall"; HttpContext.Current.Response.Redirect(new DefaultHttpRequestManager().GetQueryString(result)); ... protected override void OnCustomProcessShortcut(DevExpress.ExpressApp.CustomProcessShortcutEventArgs args) { base.OnCustomProcessShortcut(args); if (args.Shortcut["mode"] == "ExternalCall") { args.Handled = true; IObjectSpace os = CreateObjectSpace(); IModelDetailView viewModel = (IModelDetailView)FindModelView(args.Shortcut.ViewId); object obj = os.CreateObject(viewModel.ModelClass.TypeInfo.Type); DetailView view = CreateDetailView(os, args.Shortcut[ViewShortcut.ViewIdParamName], true, obj); view.ViewEditMode = ViewEditMode.Edit; args.View = view; } }
    Comments (2)

      Thanks for reply.
      I tried it, but I get this error
      Request details:
        Url: http://joshdemo/AlmaFornitoriAppalti/Default.aspx?ShortcutViewID=CampiDiValutazione_DetailView&ObjectKey=0&ScrollPosition=&ObjectClassName=
        Url referrer: http://joshdemo/joshServerWeb/tasks/1039/task-1449.aspx?taskId=1449
        SessionID: bzquxo553vqydpul1uaxvjqm
        Request type: GET
        User agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
        User IP: 127.0.0.1
        User: JOSHDEMO\Administrator
      Authenticated user: [no name]
      ================================================================================
      The error occurred:
           Type: ArgumentException
           Message: The ObjectKey is empty while the shortcut refers to a DetailView and there are '5' objects to show
           Data: 0 entries
           Stack trace:
         in DevExpress.ExpressApp.XafApplication.CreateViewParameters(IObjectSpace objectSpace, ViewShortcut shortcut)
           InnerException is null
      I tried also with http://joshdemo/AlmaFornitoriAppalti/Default.aspx?ShortcutViewID=CampiDiValutazione_DetailView&ObjectKey=1&ScrollPosition=&ObjectClassName=
      ---- (ObjectKey=1)
      but have the same error…

      Anatol (DevExpress) 14 years ago

        Hello Paolo,
        I have missed that you want to show a DetailView with the new object. In this case, you should handle the XafApplication.CustomProcessShortcut event, or override its OnCustomProcessShortcut method, as shown below:

        C#
        ViewShortcut result = new ViewShortcut("DomainObject1_DetailView", null); result["mode"] = "ExternalCall"; HttpContext.Current.Response.Redirect(new DefaultHttpRequestManager().GetQueryString(result)); ... protected override void OnCustomProcessShortcut(DevExpress.ExpressApp.CustomProcessShortcutEventArgs args) { base.OnCustomProcessShortcut(args); if (args.Shortcut["mode"] == "ExternalCall") { args.Handled = true; IObjectSpace os = CreateObjectSpace(); IModelDetailView viewModel = (IModelDetailView)FindModelView(args.Shortcut.ViewId); object obj = os.CreateObject(viewModel.ModelClass.TypeInfo.Type); DetailView view = CreateDetailView(os, args.Shortcut[ViewShortcut.ViewIdParamName], true, obj); view.ViewEditMode = ViewEditMode.Edit; args.View = view; } }

        Please let me know if you need any further help.
        Thanks,
        Anatol

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.