I want to execute a javascript function in a c# code. Here is what i did:
string jscript = "$(function () { $('#dialog-modal').dialog('open'); });";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", jscript, true);
ive no idea what to do, i didnt understand how this method works
thanks 🙂
obs.: i just write “clientScript”, but i dont know how it works
My Javascript:
<script type="text/javascript">
$(function () {
$("#dialog:ui-dialog").dialog("destroy");
var fancyboxInitOld = jQuery("#dialog-modal").dialog({
autoOpen: false,
height: 200,
width: 370,
modal: true
});
fancyboxInitOld.parent().appendTo(jQuery("form:first"));
});
</script>
My C# code
try
{
client.Send(message);
}
catch
{
string jscript = "$('#dialog-modal').dialog('open');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "clientScript", jscript, true);
}
Use
RegisterStartupScriptMethodinstead:I see you did this in your
catchblock already.RegisterClientScriptBlockis there to render client code for later use, for instance some functions.