1

I have a block of code (posted below) where if the first IF clause is satisfied, the app does not call the javascript('MyPortfolioItemExists()') function. Instead, it exits the function and goes on to process other code lines.

If drPortfolio.HasRows Then
    Dim p As Page = CType(System.Web.HttpContext.Current.Handler, Page)
    p.ClientScript.RegisterStartupScript(Me.GetType(), "Script", "javascript:'MyPortfolioItemExists()';", True)
    Return ""
    Exit Function
ElseIf drFav.HasRows = False And drPortfolio.HasRows = False Then
    Utils.ExecNonQuery("insert into UserPortfolio values ('" & PortfoName & "','" & PortfoPage & "','" & Username & "')")
    Return GeneratePortfolioContent()
End If

How can I force the javascript function to be executed?

1 Answer 1

1

p.ClientScript.RegisterStartupScript just registers the script to be executed on the client. See the documentation for more information on this function.

You can't execute Javascript on the server (unless, of course, you are writing the server-side in Javascript which you are not). Figuring out the difference between server side code and client side code is something many beginners have gotten hung up on and WebForms blurs the line even more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.