Reputation: 1007
I am calling javascript via codebehind. Giving object expected error. How can I pass some value through ShowDialog() function?
here is my code in codebehind
ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true);
and in my javascript
<script type="text/javascript">
var IRProjectID = 0;
function ShowDialog(UnitID) {
radconfirm("Are you sure you want to approve this Help Desk item?", confirmBackChecked);
IRProjectID = UnitID;
}
function confirmBackChecked(arg) {
if (arg == true) {
__doPostBack(IRProjectID, 'Approve');
}
}
</script>
Upvotes: 1
Views: 609
Reputation: 26
ClientScript.RegisterStartupScript(this.GetType(), "Call My Function", "ShowDialog("Value_here");", true);
Upvotes: 1
Reputation: 1061
I think the error is thrown by the double quotes you use around Value_here
ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true);
try this
ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog(\"Value_here\");", true);
or
ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog('Value_here');", true);
Upvotes: 0
Reputation: 953
Perhaps your calling a javascript function too soon... Try with Page.RegisterClientScriptBlock
Be carefull when you call javascript function. Be sure that it exist before!!!.
Edit:
Page.RegisterClientScriptBlock
is obsolete, use ClientScriptManager.RegisterClientScriptBlock
Upvotes: 0
Reputation: 23791
Try this
ClientScript.RegisterStartupScript(this.GetType(), "Test", "ShowDialog("+Value_here+");", true);
Upvotes: 0