SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a working solution according to below, but I want a dynamic link which is created in Createchildcontrols and included as an arguement in the function newitem but I get an JavaScript error on the page

my dynamic link:

string url = site.ServerRelativeUrl + "/_layouts/Upload.aspx?List={" + sourceList.ID + "}&RootFolder=";

I have tried

link.NavigateUrl = string.Format("javascript: newitem(" + url + ")");

sb.Append("function newitem(String URL) {");
sb.Append("options.url = URL;");  

working solution:

protected override void CreateChildControls()
link.NavigateUrl = string.Format("javascript: newitem()");

    protected override void OnPreRender(EventArgs e)

        String csname1 = "PopupScript9";

        StringBuilder sb = new StringBuilder();
        sb.Append("function newitem() {");
        sb.Append("var options = SP.UI.$create_DialogOptions();");

        sb.Append("options.url = '<some aspx site>';");  

        Type cstype = this.GetType();

        ClientScriptManager cs = Page.ClientScript;

        if (!cs.IsStartupScriptRegistered(cstype, csname1))
            cs.RegisterStartupScript(cstype, csname1, sb.ToString(), true);
share|improve this question
If you have a working solution, what is the question? – Steve B Oct 10 '12 at 9:46
exactly, what is the question? is your "working solution" is not working or you need a better way? – Diptarag Oct 10 '12 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.