Answered by:
How to create a "Select List or Library -- Webpage Dialog" for Custom Webpart Toolpart with c#

Question
-
http://img266.imageshack.us/img266/6157/dialogav8.jpg
http://img183.imageshack.us/img183/4290/toolpartjx2.jpg
The first picture shows the dialog and the second shows how this dialog has to be opened...
I want to implement such a dialog! Is this possible and if yes, how can I do this.
regards,
dbgAs12Tuesday, February 12, 2008 4:07 PM
Answers
-
Make sure you have the the right javascript files loaded in your aspx page. I am not sure how you are loading your webpart and where from. However, the functionality you are looking for is the pickertreeview.aspx page located in layouts.
You can load the page like this:
http://servername/sitename/_layouts/pickertreeview.aspx?Title=whatever&text=whatever
Here you get the webdialog window. You will have to size it correctly. After the user selects a site the ok button will becomen enabled and will do a postback and close. Load the above page and view the source to see what it is doing and to see if you can receive the postback information in your webpart. Look at the javascript function "HandleOkClicked"
Monday, February 18, 2008 3:17 PM
All replies
-
Do you want to create your own or use the one shown?Tuesday, February 12, 2008 8:15 PM
-
If there is the possibility to use something given (maybe the dialog I have linked ), I would use this. But if there is nothing I would create my own.
regards
dbgAsWednesday, February 13, 2008 7:31 AM -
One example of how SharePoint builds "WebDialogs" is the _layouts/zoombldr.aspx page. This page is used when editing the xsl in the Advanced Search Results webpart. The aspx page is composed of webcontrols. The Microsoft.SharePoint.WebPartPages.TextZoomBuilder is a control which displays text in the dialog. Can you tell me where you are launching the dialog that you displayed earlier?Wednesday, February 13, 2008 8:50 PM
-
I hope I understand you right.
If you add a normal Content Query Webpart to a zone and choose "modify shared webpart" than you can choose in the "Query" section the source. Here you find this part I show in the picture.
I want the same result, (also in the "modify shared webpart" section)
I found this javascript function as onclick= ... value for the browse button
Code Snippetfunction mso_launchListSmtPicker()
{
if (!document.getElementById) return;
var listTextBox = document.getElementById('ctl00_MSOTlPn_EditorZone_Edit0g_2c2cb80d_bbd1_4124_8438_124c5a6b0adf_CBQToolPartshowItemsFromListTextBox');
if (listTextBox == null) return;
var serverUrl = '\u002ftestsite';
var callback = function(results)
{
if (results == null
|| results[1] == null
|| results[2] == null) return;
lastSelectedListSmtPickerId = results[0];
var listUrl = '';
if (listUrl.substring(listUrl.length-1) != '/') listUrl = listUrl + '/';
if (results[1].charAt(0) == '/') results[1] = results[1].substring(1);
listUrl = listUrl + results[1];
if (listUrl.substring(listUrl.length-1) != '/') listUrl = listUrl + '/';
if (results[2].charAt(0) == '/') results[2] = results[2].substring(1);
listUrl = listUrl + results[2];
listTextBox.value = listUrl;
};
LaunchPickerTreeDialog('CbqPickerSelectListTitle','CbqPickerSelectListText','websLists','', serverUrl, lastSelectedListSmtPickerId,'','','/_layouts/images/smt_icon.gif','', callback);
}
But I never used JS before. Is this code snippet useful?
thanks and regards
dbgAs12Thursday, February 14, 2008 8:53 AM -
Please, if there is someone who know the answer: I am so in desperation, please help me...
I just need a lil' approach...
this is what I have now, but it doesn't work...
Its in my Toolpart
Code Snippetprotected override void CreateChildControls()
{//...
Button bBrowse = new Button();
bBrowse.Attributes.Add("onclick", "LaunchListPicker();");
this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "LaunchListPicker", javaScriptBuilder());//...
}
string javaScriptBuilder()
{StringBuilder sbScript = new StringBuilder();sbScript.Append(Environment.NewLine + "<script language=\"javascript\">");sbScript.Append(Environment.NewLine + "var lastSelectedListSmtPickerId = '';");sbScript.Append(Environment.NewLine + "function LaunchListPicker()");sbScript.Append(Environment.NewLine + "{");
//... hier I just build the function like I posted before
//...
return sbScript.ToString();
}
regards
dbgAs12Monday, February 18, 2008 11:54 AM -
Make sure you have the the right javascript files loaded in your aspx page. I am not sure how you are loading your webpart and where from. However, the functionality you are looking for is the pickertreeview.aspx page located in layouts.
You can load the page like this:
http://servername/sitename/_layouts/pickertreeview.aspx?Title=whatever&text=whatever
Here you get the webdialog window. You will have to size it correctly. After the user selects a site the ok button will becomen enabled and will do a postback and close. Load the above page and view the source to see what it is doing and to see if you can receive the postback information in your webpart. Look at the javascript function "HandleOkClicked"
Monday, February 18, 2008 3:17 PM -
Thank you very much.
One Question left:
I thought I can load the page with this function:
LaunchPickerTreeDialog(...)
as sharepoint did in the mso_launchListSmtPicker() function
isn't it correct?
Here is my code to open the dialog without the LaunchPickerTreeDialog()-function (it works well thank you)
Maybe here is someone who can tell me how to handle the postback
Code SnippetStringBuilder sbScript = new StringBuilder();
SPWeb web = SPContext.Current.Web;
sbScript.Append(Environment.NewLine + "<script language=\"javascript\">");
sbScript.Append(Environment.NewLine + "function LaunchListPicker()");
sbScript.Append(Environment.NewLine + "{");
sbScript.Append(Environment.NewLine + "if (!document.getElementById) return;");
sbScript.Append(Environment.NewLine + "url = location.protocol + '//' + location.hostname");
sbScript.Append(Environment.NewLine + "dialogposition='width='+400+',height='+500+',top='+50+',left='+50;");
sbScript.Append(Environment.NewLine + "window.open('_layouts/pickertreeview.aspx', 'dialog', dialogposition); ");
sbScript.Append(Environment.NewLine + "}");
sbScript.Append(Environment.NewLine + "</script>");
regards
dbgAs12Tuesday, February 19, 2008 7:59 AM -
Hello,
have you allready found a solution?Check this example out to see how it works to open a small Text-Editor Popup in the Toolpart
http://www.codeplex.com/sptoolbox/Release/ProjectReleases.aspx?ReleaseId=11150
The Source code is like this. Maybe it will work with the ListPicker the same way:
Please let me know if you found a way!
protected
override void CreateChildControls(){
//.... building presentation html Table
//Build Text Box
retQry = new HiddenField();retQry.ID =
"Query_HIDDEN";cell.Controls.Add(retQry);
new LiteralControl(" <input type=\"button\" value=\"Editor...\" id=\"" + editorId + "_QueryOverride_Builder\" title=\" Click to Use Builder \" onclick=\"javascript:" + string.Format("MSOPGrid_doBuilder('{0}?culture={1}', {2}, '{3}')", SPHttpUtility.EcmaScriptStringLiteralEncode(builderUrl), Thread.CurrentThread.CurrentUICulture, SPHttpUtility.EcmaScriptStringLiteralEncode(editorId), dialogFeatures) + ";\" />"));
cell.Controls.Add(row.Cells.Add(cell);
//build the rest of the presentation table
Wednesday, April 23, 2008 8:44 PM -
Has any one figured out how to handle the post back. It appears some sort of array is created by the javascript, but maybe i'm way off base since I am still relatively new to the whole SharePoint / javascript scene. Here is our sample code, but this returns [object] in the text box.
Code SnippetHtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
HtmlTableCell cell2 = new HtmlTableCell();
//Build Text Box
txt = new TextBox();
txt.ID = "Query_HIDDEN";
cell2.Controls.Add(txt);
string builderUrl = "/_layouts/pickertreeview.aspx";
string editorId = ClientID + '_' + txt.ID;
string dialogFeatures = "dialogHeight:340px;dialogWidth:430px;help:no;status:no;resizable:yes";
cell2.Controls.Add(new LiteralControl(" <input type=\"button\" value=\"Editor...\" id=\""
+ editorId
+ "_QueryOverride_Builder\" title=\" Click to Use Builder \" onclick=\"javascript:"
+ string.Format("MSOPGrid_doBuilder('{0}?culture={1}', {2}, '{3}')",
SPHttpUtility.EcmaScriptStringLiteralEncode(builderUrl),
Thread.CurrentThread.CurrentUICulture,
SPHttpUtility.EcmaScriptStringLiteralEncode(editorId),
dialogFeatures)
+ ";\" />"));
row.Cells.Add(cell1);
row.Cells.Add(cell2);
table.Controls.Add(row);
this.Controls.Add(table);
We're very perplexed at how to get the objects in the array OUT of the array... can anybody shed anylight on the subject?
Thanks
Tuesday, June 24, 2008 8:18 PM -
Did you guys find any solution to this?
I am able to open up the dialog and send the value to the text box (Darren's post really helped me), but now, how do I do to populate a listbox or combobox within the editorpart based on the list selected?, pretty much the same as in the "I Need To.." EditorPart.
Any Idea?- Edited by Saul Preciado Friday, September 12, 2008 5:02 PM Typo
Friday, September 12, 2008 5:00 PM