0

I have following function in .js file and i need to call it from code behind page after saving a record.

I have registered scipt file in aspx page

aspx file

  <script type="text/javascript" src="/scripts/visit-flash-report.js"></script>

.js file

function reloadDocTab() {

alert('hello');
$('#frmDocs').attr('src', $('#frmDocs').attr('src'));
}

Code behind page

I have tried the function but it is not working

Page.ClientScript.RegisterOnSubmitStatement(Me.[GetType](), "reload function", "return reloadDocTab();")
user1263981
  • 2,953
  • 8
  • 57
  • 98

3 Answers3

0

Try this:

.aspx

<script type="text/javascript" src="/scripts/visit-flash-report.js"></script>
<asp:Literal runat="server" ID="litJS" />

.cs

litJS.Text = @"<script type='text/javascript'>alert('hello');</script>";

If you dont need to execute the script on a different postback you might want to assign an empty string to the literal.

0

If I understand what your trying to do. You want to save the record on postback then when the page reloads call the javascript function.

Try this:

PageBody.Attributes.Add("onload", "reloadDocTab()");
  • no, i don't want to call reloadDocTab() on postback. I want to call it when i click certain button which will save record in DB and then refresh tab. – user1263981 Jun 19 '14 at 15:42
0

Try one of these:

Page.ClientScript.RegisterStartupScript(this.GetType(), "ScriptKey", "reloadDocTab()", true);

OR

ClientScript.RegisterStartupScript(this.GetType(), "ScriptKey", "reloadDocTab()", true);

OR

ScriptManager.RegisterStartupScript(this.GetType(), "ScriptKey", "reloadDocTab()", true);

And i think you might need to refrence the .JS file in the head tag

<head runat="server">
    <script src="~/scripts/visit-flash-report.js"></script>
</head>
Ghanem
  • 93
  • 2
  • 2
  • 14