Click here to Skip to main content
16,016,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Following code is working perfectly

in .aspx page
========================================
ASP.NET
<script type="text/javascript">
  function openDialog()
  {

    var ur="http://google.com"
    var options =
    {
      url: ur,
      width: 800,
      height: 600,
      title: "Event Details",
    };
    SP.UI.ModalDialog.showModalDialog(options);
  }
</script>

<asp:Literal ID="htm" runat="server"></asp:Literal>

in aspx.cs page I am calling the function as follows
===================================================
C#
htm.Text = "<a href='#', onclick='openDialog()'>"

The above code is working properly


But If I pass "http://google.com" as parameter (as below) it is not working


in .aspx page
========================================
ASP.NET
<script type="text/javascript">
  function openDialog(ur)
  {

    var options =
    {
          url: ur,
      width: 800,
      height: 600,
      title: "Event Details",
    };
    SP.UI.ModalDialog.showModalDialog(options);
  }
</script>

<asp:Literal ID="htm" runat="server"></asp:Literal>

in aspx.cs page I am calling the function as follows
===================================================
C#
string ur="http://Google.com"
htm.Text = "<a href='#', onclick='openDialog("+ur+")'>"

Can any one correct the
Posted
Updated 18-Sep-11 18:07pm
v2
Comments
Prerak Patel 19-Sep-11 0:07am    
Corrected code blocks.

1 solution

I don't think you're escaping your text string correctly. Try this instead:

C#
string ur="http://Google.com";
htm.Text = string.Format(@"<a href="#" önclick="openDialog('{0}');">{0}</a>", ur);


A question though, why on earth are you using a literal to display a hyperlink on a page?

What's wrong with:

<asp:HyperLink ID="hyperLink" runat="server" NavigateUrl="#"  />


And:

C#
string ur="http://Google.com";
hyperLink.Text = ur;
hyperLink.OnClientClick = string.Format("openDialog('{0}');", ur);


?
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900