Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

LinkButton OnClientClick Event calling a javaScript Function to open ModalDialog

$
0
0

I am using an ASP.NET repeater control in which i have added 2 controls (LinkButton and Label)

I am binding the LinkButton and Label with Title and URL of a SharePoint ListItem respectively.

OnClick of the LinkButton should open the Display Form(DispForm.aspx) of the ListItem in a ModalDialog with specific Height and Width.

But when i click on the LinkButton, the ModalDialog flashes and disappears in about 5seconds.

Here's the code i have written.

(.ascx Code)

<scripttype="text/javascript">

   function demoCallback(dialogResult, returnValue)

   {

       SP.UI.Notify.addNotification('Operation Successful!');

       SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

   }

   function openDialog(title1, url1) {

       var options = {

           title: "Announcements - "+ title1,    

           width: 600,

           height: 400,

           url: url1,

           dialogReturnValueCallback: demoCallback

       };

       SP.UI.ModalDialog.showModalDialog(options);

       //return false;

   }  

</script>

<asp:RepeaterID="Repeater2"runat="server"OnItemDataBound="Repeater_dataBound">

   <ItemTemplate>      

       <table>         

          <tr>

              <td>

                   <li>

                   </li>

              </td>  

              <td>

                   <asp:LinkButtonID="lnkBtnTitle"runat="server"Style="position:relative"Text='<%# Eval("Title")%>'/>            

               </td>

              <td>

                  <asp:LabelID="lblUrl"runat="server"Visible="False"Text='<%# Eval("Url")%>'></asp:Label>

              </td>

          </tr>

       </table>   

   </ItemTemplate>

</asp:Repeater>

(.ascx.cs Code)

       protectedvoid Page_Load(object sender, EventArgs e)

       {

           SPWeb web =SPContext.Current.Web;

           SPList list = web.Lists["Announcements"];

           DataTable dt1 =newDataTable();

           SPQuery query =newSPQuery();

           query.Query = "<OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy>";

           query.RowLimit = 5;

           

           SPListItemCollection items = list.GetItems(query);

           try

           {          

               DataColumn dc;

               DataColumn dc1;

               dc = newDataColumn("Title",Type.GetType("System.String"));

               dc1 = newDataColumn("Url",Type.GetType("System.String"));

               dt1.Columns.Add(dc);

               dt1.Columns.Add(dc1);

               string title =string.Empty;

               string url =string.Empty;

               DataRow dr;

               foreach (SPListItem item in items)

               {

                   title = item["Title"].ToString();

                   url = web.Url + "/Lists/"+ list.Title +"/DispForm.aspx?ID="+ item.ID;

                  

                   dr = dt1.NewRow();

                   //dr["Title"] = "<a href=" + url + ">" + title + "</a>";

                   dr["Title"] = title;

                   dr["Url"] = url;

                   dt1.Rows.Add(dr);

               }            

               Repeater2.DataSource = dt1;

               Repeater2.DataBind();            

           }

           catch (Exception Ex)

           {

               throw Ex;

           }

       }

       protectedvoid Repeater_dataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)

       {        

           LinkButton lnkBtn = (LinkButton)e.Item.FindControl("lnkBtnTitle");

           Label lbl = (Label)e.Item.FindControl("lblUrl");

           lnkBtn.OnClientClick = string.Format("openDialog('{0}','{1}');",Convert.ToString(lnkBtn.Text),Convert.ToString(lbl.Text));

       }

When i check the LinkButton properties on my site, the Address URL is shown as

javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl33$g_b3b02385_9300_490d_b08c_1793781f2cc4$Repeater2$ctl00$lnkBtnTitle", "", true, "", "", false, true))

Please suggest a solution thru which i can open the Form in Modal Dialog


Viewing all articles
Browse latest Browse all 25064

Trending Articles