This is a migrated thread and some comments may be shown as answers.

Javascript Execution -- Alert Message

1 Answer 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 06 Sep 2011, 06:50 PM

Hello All,

    I am developing a web application in which i have RadGrid. In the RadGrid Edit button, I am calling a Javascript function which will get the geocodes and writes in to the hidden fields. Now the problem is, If I put the alert message in that function,  I can see the geocodes properly. If i remove the alert message, the hidden fields are blank.

I guess the  probelm is, I am reading those hidden field values from code behind before the page loads completly.

Here is my javascript

        function initiate_geolocation() {  
                 navigator.geolocation.getCurrentPosition(handle_geolocation_query);  
                alert('delay to get the geocodes');
             return false;
         }

 

       function handle_geolocation_query(position){  
        enableHighAccuracy: true
                                
              
                  var lat = '<%=hidLat.ClientID %>';
                   var lon  = '<%= hidLong.ClientID %>';
                
                                           
                  document.getElementById(lat).value = position.coords.latitude;
              
                  document.getElementById(lon).value = position.coords.longitude;
                  
                 } 

And in the code behind, in the item data bound event

i added the attributes for the edit button and called the javascript function

  Dim editButton As ImageButton = DirectCast(item.FindControl("EditButton"), ImageButton)
  editButton.Attributes.Add("OnClick", "initiate_geolocation();")


Im trying to access those hidden fields in the update command event of the Radgrid

Is there something to do to let the form load completly and then read those hidden fields? How do I get out of this problem?

Appreciate the Help!

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Sep 2011, 10:59 AM
Hi Jagat,

I would recommend that you use a client-side only approach:
<script type="text/javascript">
    function pageLoad()
    {
        var grid = $find('<%= RadGrid1.ClientID %>');
        if (grid._editIndexes.length > 0)
        {
            navigator.geolocation.getCurrentPosition(handle_geolocation_query);
        }
    }
</script>

I hope this helps.

Regards,
Daniel
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Jagat
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or