Adding javascript / jquery on code behind ASP .net using ScriptManger

Posted: February 3, 2012 in web

you can do it with a number of ways. this is one of them.

            string scriptstring = @"
            $('#parkreport').live('pageinit', function (event) {
                $('#selectlocation').change(function(){
                        
                    if($(this).val() == 'enter'){
                        $('#enterlocation').show();
                    }
                    else
                        $('#enterlocation').hide();

                });
                $('#submit').click(function(e){
                    e.preventDefault();
                    if ($('#PersonName').val() == '') {
                        alert('Please enter your name.');
                        return (false);
                    }
                    if ($('#ctype').val() == '') {
                        alert('Please select waste type.');
                        return (false);
                    }
                    if ($('#cComments').val() == '') {
                        alert('Please enter your comment or concern.');
                        return (false);
                    }
                    if ($('#selectlocation').val() == '') {
                        alert('Please enter your location.');
                        return (false);
                    }

                        if ($('#selectlocation').val() == 'current') {
                           if(navigator.geolocation) {
                                navigator.geolocation.getCurrentPosition(function(position) {
                                    $('#lat').val(position.coords.latitude);
                                    $('#lng').val(position.coords.longitude);
                                },
                                function(){
                                    alert('Location not found')
                                }); //eof navigator
                            }
                            else
                                alert('Location not found')

                        }

                        $('#Form1').submit();

                }); //eof click
            }); // eof pageinit
        ";
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "sas", scriptstring, true);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s