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?
The # sign is not an issue at all.
dialogmethod 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").dialogcall 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 theOnClientClicklike that:Check this question for more info about that.
EDIT:
My version available online:
Everything is in
Default.aspxandDefault.aspx.csfiles, controls are created inDefault.aspx.designer.cs. You can post your version via CodeRun to show us the context and other elements that may cause problems.