SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

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 created custom list web part and using that web part in home page. when i click on item its not opening in dialog. I used below code.

Can anyone suggest me what is the problem ?

     SPQuery query = new SPQuery();
                                     query.Query = "<OrderBy><FieldRef Name='ID'     Ascending='False' /></OrderBy>";
                            query.RowLimit = Convert.ToUInt16(RowLimit);
                            SPList list = web.Lists[ListName];
                            SPListItemCollection listItemsCollection = list.GetItems(query);
                            foreach (SPListItem listItem in listItemsCollection)
                                TableRow tableRow = new TableRow();
                                TableCell tableCell = new TableCell();
                                HyperLink link = new HyperLink();

                                string docName = listItem.Title;
                                link.Text = docName;
                                   link.NavigateUrl = web.ParentWeb.Url  + list.DefaultDisplayFormUrl + "?id=" + listItem.ID + "&IsDlg=1";

                                catch (Exception ex)
                                    link.NavigateUrl = web.Url + list.DefaultDisplayFormUrl + "?id=" + listItem.ID ;

                                //link.Target = "_parent";
share|improve this question
Here is a similar question:… – Chloraphil Mar 14 '13 at 12:02

When looking at the code I can't see anything that opens it in a dialog. Just ordinary links. Add "javascript:OpenDialog(here you puit that url) to link. Add this javascript as well:

The script can be found here:

or here

function OpenDialog(url)

   //Using a generic object.
   var options = {
   title: "My Dialog Title",
   width: 400,
   height: 600,
   url: url };

share|improve this answer
Addition: showModalDialog appends IsDlg=1 to the link provided, so no need to include that in the url parameter. – Jussi Palo Mar 14 '13 at 12:26
Thanks For ur reply. Can you tell me how to add and call javascript function in .ascx.cs file in .net 2012 – janakiakula Mar 14 '13 at 12:28
You save the javascript in a js file which you deploy to either the hive or library. Then you reference it through the ClientScriptManager.RegisterClientScriptInclude. Info can be found at:… – Magnus Hansson Mar 14 '13 at 13:01

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.