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>';");
sb.Append("SP.UI.ModalDialog.showModalDialog(options);");
sb.Append("}");
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
cs.RegisterStartupScript(cstype, csname1, sb.ToString(), true);
}
}