0

I am calling a jQuery Modal Dialog function from ASP.Net and I am passing some parameters to it. One of the parameters contains a # symbol across and for this reason, the jQuery modal dialog call does not execute.

What's the way to resolve this problem? I tried escaping the character by doing a replace of the string '#' with this '\#' but still doesn't work out.

Thanks.

Code from the top of my head..

String var1 = "#3 and #4 should be on the list.";
lnkDetails.OnClientClick = "openDialog('" + var1 + "');

And the normal jQuery dialog function:

function openDialog(varPassed) {
            $("#divModal").dialog({
                width: 600,
            });

            $('#<%= label1.ClientID %>').text(varPassed);

Update: It seems the modal does not show up because of this line:

$('#<%= label1.ClientID %>').text(varPassed);

When the value being assigned to the label which is inside the div of the modal dialog itself, the modal window does not show up.

This is the modal window.

<div id="divMaterialDetails" title="Material Details" style="display:none" >
    <asp:Label ID="label1" runat="server" CssClass="formLabel"/>
</div>

If I commented out the assignment of the value, the modal shows up.

So how would I be able to assign the value passed to the modal to the label so that the modal would show up?

Angelo
  • 1,578
  • 3
  • 20
  • 39

1 Answers1

1

The # sign is not an issue at all. dialog method is not part of jQuery itself, but it is a part of jQuery UI. Did you include jQuery UI library as well, as compatible version of jQuery? Comment out/remove $("#divModal").dialog call and see if everything is fine. I tested this with and without this part and with this line it was not executing the line after the one that was causing error. When I included jQuery UI it started to work.

In general, if you're not sure what could be wrong with your code, try commenting out some parts you think may be causing problems as long as commenting something out/removing will fix the problem. It's much easier to find out what's going on by elimination of possible "trouble-makers" one by one. And, of course, use debugger - for Firefox the Firebug extention with JavaScript console is very usefull. You can read error messages that can lead you the the real source of the problem.

And BTW, if you don't want browser to follow clicked link, consider adding return false; to the OnClientClick like that:

lnkDetails.OnClientClick = "openDialog('" + var1 + "');return false;";

Check this question for more info about that.

EDIT:

My version available online:

Everything is in Default.aspx and Default.aspx.cs files, controls are created in Default.aspx.designer.cs. You can post your version via CodeRun to show us the context and other elements that may cause problems.

Community
  • 1
  • 1
Konrad Gadzina
  • 3,407
  • 1
  • 18
  • 29
  • Yes, I have the jQeryUI libraries referenced. Surprisingly, this only happens when the string being passed contains the # sign. – Angelo Feb 08 '13 at 07:25
  • @Angelo I edited my answer with links to source and compiled version of what is working for me. You can try using CodeRun to host essential part of your code that is causing problem so we can investigate it. – Konrad Gadzina Feb 08 '13 at 11:04
  • I think I've found the bug. I will update the question above. – Angelo Feb 11 '13 at 15:28