0

Currently I have strClsCafeListHTML=fGetCafeList() in the Page Load event in a CafesNearMe.aspx.vb file.

This displays a list of Cafes in the page middle section when the page is opened.

How do I delay that from firing until the JavaScript similar to http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation has put the latitude and longitude values into 2 hidden fields, HiddenFieldCurrentLat and HiddenFieldCurrentLong?

(I want fGetCafesList() to inspect those two hidden fields so that the backend SQL can filter for <10 miles.)

1 Answer 1

2

The VB Page_Load event will always happen before the Javascript begins. You could do a workaround, like put your strClsCafeListHTML=fGetCafeList() on a button click event, then trigger that button click via JavaScript after the hiddenfields are populated. If using Jquery, you would do something along the lines of this:

Jquery

$(document).ready(function() {
   //populate hidden fields etc
   $('#myButton').trigger("click");
)};

HTML

<asp:Button runat="server" id="myButton" clientIDMode="static" style="display: none;" onClick="myButton_click"></asp:Button>

VB Code-behind

Protected Sub myButton_Click(sender As Object, e As EventArgs)

    'Do code behind stuff
    'strClsCafeListHTML=fGetCafeList()

End Sub

The concern here is that the button click event will fire another postback, however this will always be the case when running server-side code. If the reloading of the page is an issue, you could try using an <asp:UpdatePanel> or go down the road of AJAX.

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.