0

I have a button click action that I need to call some javascript in from the code behind, in order for it to execute after the button click action code has executed

the function works fine when called from the aspx file, the js file is being set in the page_load event as so:

Dim s1 As String = "<script type=""text/javascript"" src=""Default.js" & rnd & """></script>"
Me.ClientScript.RegisterStartupScript(Me.GetType, "DefaultLnks", s1)

this is the button, its legacy code using devexpress controls :(

<dx:ASPxButton ID="btnLoadData" runat="server" Text="Refresh Data"></dx:ASPxButton>

this is what i have in the code behind to execute at the end of the button click event:

Dim jsExecute = "<script type='text/javascript'>refreshData();</script>"
Page.ClientScript.RegisterStartupScript(Me.GetType(),"refreshData()", jsExecute)

the problem is it is not reaching the function when being called, no errors, it just never gets there. I need it to execute from the code behind as it needs to happen after some data import that happens on the button click event.

6
  • Have you checked the rendered page to make sure the script is there? And have you looked in the browser's developer tools (press F12) console to see if there are any JavaScript errors? Does a simple "<script type='text/javascript'>alert('Hello!');</script>" work? Commented Aug 16, 2019 at 8:20
  • Hi Andrew, sorry I should have mentioned in the original post that they have been attempted, i was able to get a simple console.log to work Commented Aug 16, 2019 at 10:04
  • That's OK, some people don't know about the developer tools so I wanted to be sure. So, if a simple console.log works, does it also work inside the refreshData() function? Commented Aug 16, 2019 at 10:29
  • that isnt working either. everything ive tried basically hints that the page isnt picking up the JS file, but then it is working on other buttons that are client side actions. I was considering it might be a lifecycle thing, but still its being set in the page load so it should work Commented Aug 16, 2019 at 11:00
  • Just for testing, if you add some element, say a <div>, and set its onclick to run refreshData(), does that work? Commented Aug 16, 2019 at 11:31

1 Answer 1

0

I would suggest changing the button handler to a Webmethod and calling it with AJAX. Any front end stuff you want to happen after the button is clicked you can do in the JS click handler, and you can still call your other codebehind methods in the Webmethod.

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.