Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 453261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:09:15+00:00 2026-05-12T22:09:15+00:00

In a scaffolded page in ASP.NET Dynamic Data, if the entity has a foreign

  • 0

In a scaffolded page in ASP.NET Dynamic Data, if the entity has a foreign key field, and the value you seek is not in the the primary key table, i.e. is not in the drop-down, you have to abandon your edits to the entity, add the sought foreign key value to its table, and return to your original entity.

How could I go about adding a ‘New’ link/button to the foreign key field template, that would open a new window (make a Panel visible) where you can add the sought value, and then refresh the drop-down?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:09:16+00:00Added an answer on May 12, 2026 at 10:09 pm

    You mean like in the django admin ui ;).
    I’m currently trying to implement that feature, i’ll post the code here if I get it to work.

    EDIT:

    Ok, I got that to work, complete django style… It’s kinda long to explain but simple in fact.

    Files to create:

    A admin_popup.master to have a nice popup page (copy the admin.master without the header).

    A popup_Insert.aspx with admin_popup.master as master. (copy the Insert.aspx)

    Modifications

    To your admin.master.cs:
    add this:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
    
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "refresh_fks", @"
        var fk_dropdown_id;
        function refresh() {
            __doPostBack(fk_dropdown_id,'refresh');
        };", true);
    }
    

    In your admin_popup.master, add these attributes to the body tag (it’s used to resize the poup)

    <body style="display: inline-block;" onload="javascript:resizeWindow();">
    

    In your admin_popup.master.cs

    protected override void  OnInit(EventArgs e)
    {
        base.OnInit(e);
    
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "refresh_fks", @"
        var fk_dropdown_id;
        function refresh() {
            __doPostBack(fk_dropdown_id,'refresh');
        };", true);
    
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "resize_window", @"function resizeWindow() {
            window.resizeTo(document.body.clientWidth + 20, document.body.clientHeight + 40);
            window.innerHeight = document.body.clientHeight + 5;
            window.innerWidth = document.body.clientWidth;
        }", true);
    
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "update_parent", @"function updateParent() {
            window.opener.refresh();
        }", true);        
    }
    

    In popup_Insert.aspx.cs, replace these two functions:

    protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e) {
        if (e.CommandName == DataControlCommands.CancelCommandName)
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "self.close();", true); 
    }
    
    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) {
        if (e.Exception == null || e.ExceptionHandled) {
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "window.opener.refresh(); self.close();", true); 
        }
    }
    

    In ForeignKey_Edit.ascx, add a LinkButton (ID=LinkButton1) and in ForeignKey_Edit.ascx.cs, replace that function

    protected void Page_Load(object sender, EventArgs e) {
        if (DropDownList1.Items.Count == 0)
        {
            if (!Column.IsRequired) {
                DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
            }
    
            PopulateListControl(DropDownList1);
            LinkButton1.OnClientClick = @"javascript:fk_dropdown_id = '{0}';window.open('{1}', '{2}', config='{3}');return false;".FormatWith(
                DropDownList1.ClientID,
                ForeignKeyColumn.ParentTable.GetPopupActionPath(PageAction.Insert),
                "fk_popup_" + ForeignKeyColumn.ParentTable.Name, "height=400,width=600,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
        }
        if (Request["__eventargument"] == "refresh")
        {
            DropDownList1.Items.Clear();
            if (!Column.IsRequired)
            {
                DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
            }
    
            PopulateListControl(DropDownList1);
            DropDownList1.SelectedIndex = DropDownList1.Items.Count - 1;
        }
    }
    

    And finally the two extentions functions I use (put it where you want to):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    using System.Web.DynamicData;
    using System.Web.UI;
    
    public static class Utils
    {
        [DebuggerStepThrough]
        public static string FormatWith(this string s, params object[] args)
        {
            return string.Format(s, args);
        }
    
        public static string GetPopupActionPath(this MetaTable mt, string action)
        {
            return new Control().ResolveUrl("~/{0}/popup_{1}.aspx".FormatWith(mt.Name, action));
        }
    }
    

    In your global.asax, register the new route by changing that line:

    Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert|popup_Insert" }),
    

    Ok I hope i didn’t forgot anything… It certainly could be improved, but it works.
    Ok I hope some people will fint that useful, it makes ASP.NET Dynamic Data a lot more better ;). I’m goind to take a look at many-to-many relationships now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I generate a default scaffold, the display tags on show.html.erb have <%=h @broker.name
I am running ruby script/generate scaffold or ruby script/generate model and I know the
Is there any thing in PHP to create basic scaffold, like in Rails? EDIT:
I created a Rails application normally. Then created the scaffold for an event class.
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.