Reputation: 97
I have to call a jConfirm function (jquery alert library) via c# programmatically. I include the .js library in the master page of my site like this:
<script type="text/javascript"
src='<%# Page.ResolveClientUrl("~/Scripts/jquery-1.7.2.min.js") %>'></script>
<script type="text/javascript"
src='<%# Page.ResolveClientUrl("~/Scripts/jquery.alerts.js") %>'></script>
...and call the method via c# in this way:
Page.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "alert", @"
<script type=""text/javascript"" language=""javascript"">
jConfirm('Are you sure?', 'title', function(answer) {
if (answer)
alert('ok');
else
alert('ko');
}); return false;
</script>");
But it does not work... if i call in the same way for example a jAlert function everything goes fine, so i don't think is an import problem.
Any suggestion?
Upvotes: 0
Views: 171
Reputation: 97
I finded the solution... it was a really naive reason!
<script type="text/javascript"
src='<%# Page.ResolveClientUrl("/Scripts/jquery-1.7.2.min.js") %>'></script>
<script type="text/javascript"
src='<%# Page.ResolveClientUrl("/Scripts/jquery.alerts.js") %>'></script>
It seems that with the charachter '~' in the relative path this script does not work... without it goes fine.
Upvotes: 0
Reputation: 3681
Wrap it inside a function
Page.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "alert", @"
<script type=""text/javascript"" language=""javascript"">
function FooAlert(){
jConfirm('Are you sure?', 'title', function(answer) {
if (answer)
alert('ok');
else
alert('ko');
}); return false;
}
</script>");
Upvotes: 1