Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Hi.... I am getting a problem in javascript in aspx page... i have included an onclick event in a asp button like this.... aspx page whole code:
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserUploads.aspx.cs" Inherits="QlixooWeb.UserUploads" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="FlashUpload" Namespace="FlashUpload" TagPrefix="FlashUpload" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"  runat="server">
    <title>Qlixoo::Uploads</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
 
    <script src="js/jquery-latest.js" type="text/javascript"></script>
 
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
        type="text/javascript"></script>
 
    <style type="text/css">
        span
        {
            cursor: pointer;
        }
        .uploads
        {
            width: 625px;
            height: 335px;
            border: 1px solid #353535;
            border-radius: 7px;
            background-color: #363636;
            display: none;
        }
    </style>
 
    <script type="text/javascript">
    function confirmUpload()
    {
    alert("Uploaded Successfully");
    window.location.href = "UserUploads.aspx?Tag=1";
    }
    ///Mb--
    function ShowVideoUpload()
    {
    $(document).ready(function(){
         $("#div_VideoUpload").show();
         $("#div_FlashUpload").hide();
    });
    }
    function ShowFlashUpload()
    {
    $(document).ready(function(){
         $("#div_FlashUpload").show();
         $("#div_VideoUpload").hide();
    });
    }
    ///Mb--Google Places
    function initialize() 
    {
            ///Mb--Own
            var txtM = document.getElementById("hdn_Tagging").value;///Id s of textbox assigned in code behind MB--
            txtM = txtM.slice(0, -1);
            var arrTxtM = txtM.split(","); 
            ///*Mb--
            var mapOptions = {
                center: new google.maps.LatLng(-33.8688, 151.2195),
                zoom: 13,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);
            var input, autocomplete;
            ///Mb--Looping the Id s of textbox
            for(var i=0;i<arrTxtM.length;i++)
            {
            input = document.getElementById(arrTxtM[i]);
            autocomplete = new google.maps.places.Autocomplete(input);
            }
            ///*Mb--
            var marker = new google.maps.Marker({
                map: map
            });
            google.maps.event.addListener(autocomplete, 'place_changed', function () {});
      }
      google.maps.event.addDomListener(window, 'load', initialize);
      ///$('#btn_Tagging').click(DoneClick);
    ///*Mb--
    ///Mb--Done Button
    </script>
 
</head>
<body>
    <form id="form1"  runat="server">
    <center>
 
        <script type="text/javascript">
              
function DoneClick() {
 
    alert("OO");
 
    var checkLocation = "";
 
    var txtMM = document.getElementById("hdn_Tagging").value; ///Id s of textbox assigned in code behind MB--

    txtMM = txtMM.slice(0, - 1);
 
    var arrTxtMM = txtMM.split(",");
 
    for (var j = 0; j < arrTxtMM.length; j++) {
 
        var Loc = document.getElementById(arrTxtMM[j]).value;
 
        if (Loc == "") {
 
            checkLocation = "";
 
            break;
 
        } else {
 
            checkLocation += Loc + ":";
 
        }
 
    }
 
    if (checkLocation != "") {
 
        var url = 'Handler/newExifDetails.ashx?Id=' + txtMM + '&Location=' + checkLocation + '';
 
        alert(url);
 
        alert("yes");
 
        $.getJSON(url, function (json) {
            alert(json);
            console.dir(json);
 
            $.each(json, function (i, weed) {
 
                alert("good");
 
                var res = weed.res;
 
                alert(res);
 
                if (res == null) {
 
 
 
                } else {
 
                    window.top.location.href = "Dashboard.aspx";
 
                }
 
 
 
            });
 
 
 
 
 
 
 
        });
 
 
 
        ///Mb--Handler

        //             $(document).ready(function() {

        //                //alert("Id: " + txtMM);

        //                //alert("Location "+checkLocation);

        //                $.ajax({

        //                type: "POST",

        //                contentType: "application/json; charset=utf-8",

        //                url: "/handler/ExifDetails.ashx",

        //                data: { Location: '' + checkLocation + '', Id: '' + txtMM + '' },                  

        //                dataType: "script",

        //                success: function(data)

        //                {  

        //                    alert(data);

        //                    window.top.location.href = "Dashboard.aspx";

        //                                  

        //              }

        //              });  

        //             });

    } else {
 
        alert("Please pick the locations for all objects");
 
    }
 
 
 
}
        </script>
 
        <div style="padding: -1px 35px 0px 0px">
            <%--117--%>
            <div style="width: 100%" class="titletext">
                <span  önclick="ShowFlashUpload()">Add Memories</span> / <span>
                    <%--onclick="ShowVideoUpload()"--%>
                    Video Memories</span> / Facebook Memories
            </div>
            <div id="div_FlashUpload"  runat="server" style="width: 625px; height: 335px; border: 1px solid #353535;
                border-radius: 7px; background-color: #363636">
                <FlashUpload:FlashUpload ID="flashUpload"  runat="server" FileTypeDescription="Images"
                    FileTypes="*.gif; *.png; *.jpg; *.jpeg; *.wmv;*.mp4;*.mpg;*.flv;*.mp3"  önUploadComplete="confirmUpload();"
                    TotalUploadSizeLimit="999999999" UploadFileSizeLimit="999999999" UploadPage="Uploader.aspx" />
            </div>
            <div id="div_FlashReturn"  runat="server" class="uploads">
                <asp:DataList ID="dl_tagging" runat="server" RepeatDirection="Horizontal" RepeatColumns="2"
                    OnItemDataBound="dl_tagging_ItemDataBound">
                    <ItemTemplate>
                        <div style="width: 290px; margin: 7px;">
                            <img alt="alt" id="img_Tagging"  runat="server" style="width: 100px; height: 100px;
                                padding-left: 80px" />
                            <input type="text" id='<%#Eval("UpListId") %>' style="width: 260px; margin-top: 9px" />
                            <%----%>
                        </div>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="lblEmpty" Text="Not any images for tagging!!" Style="color: Red; width: 140px"
                            runat="server" Visible='<%#bool.Parse((dl_tagging.Items.Count==0).ToString())%>'>
                        </asp:Label>
                    </FooterTemplate>
                </asp:DataList>
                <div style="margin: 12px 12px 12px 40px;">
                    <asp:Button ID="btn_Tagging" CssClass="button" UseSubmitBehavior="false" Text="Done"
                        runat="server" OnClientClick="DoneClick()"/><%--btn_Tagging_Click--%>
                    <%--                    <button id="btn_Tagging" class="button"  önclick="DoneClick()">
                        Done</button>--%>
                    <div id="map_canvas" style="display: none">
                    </div>
                    <asp:HiddenField ID="hdn_Tagging" runat="server" />
                </div>
                <div id="div_VideoUpload"  runat="server" class="uploads">
                    <div style="float: left; padding-removed 4px" class="subheading">
                        Please do not close this window while uploading,before getting 'Save Video' Option</div>
                    <iframe id="iframeVideoupload"  runat="server" target="_Parent" frameborder="0" width="100%"
                        scrolling="no" height="300px" src="">
                    </iframe>
                </div>
                <div id="div_VideoReturn"  runat="server" class="uploads">
                    <asp:Button ID="btnsave" runat="server" CssClass="button" OnClick="btnVideosave_Click"
                        Text="Save" />
                    <asp:Label ID="lbl_msg" runat="server" CssClass="error"></asp:Label>
                </div>
            </div>
        </div>
    </center>
    </form>
</body>
</html>
 

Code behind of this is:
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLib_MDL;
using ClassLib_BLL;
 
namespace QlixooWeb
{
    public partial class UserUploads : System.Web.UI.Page
    {
        public static readonly UserUploadsMDL oUserUploadsMdl = new UserUploadsMDL();
        public static readonly UserUploadsBLL oUserUploadsBll = new UserUploadsBLL();
        /// <summary>
        /// Mb--Page Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserId"] == null)
                    Page.RegisterStartupScript("RedirectScript1", "<script type=text/javascript>window.parent.location = 'Login.aspx'</script>");
                else if (Session["UserId"].ToString() == "0")
                    Page.RegisterStartupScript("RedirectScript2", "<script type=text/javascript>window.parent.location = 'Login.aspx'</script>");
                else
                {
                    oUserUploadsMdl.UserId = Convert.ToString(Session["UserId"]);
                    string test = Convert.ToString(Session["Tagging"]);
                    if (Request.QueryString["Tag"] != null)
                    {
                        Session["Tagging"] = "0";
                        GetTagImages(Convert.ToString(Session["UserId"]));
                    }
                    else
                    {
                        if (Request.QueryString.HasKeys())
                        {
                            if (Request.QueryString["ThumbUrl"] != null)
                                //oUserUploadsMdl.WeediohThumb = Request.QueryString["ThumbUrl"].ToString();
                            if (Request.QueryString["VideoUrl"] != null)
                            {
                                //oUserUploadsMdl.WeediohUrl = Request.QueryString["VideoUrl"].ToString();
                                ///
                                oUserUploadsMdl.Latitude = 0;
                                oUserUploadsMdl.Longitude = 0;
                                oUserUploadsMdl.GpsDate = "0";
                                ///
                                div_VideoReturn.Style.Value = "display:";
                                div_VideoUpload.Style.Value = "display:none";
                            }
                        }
                        flashUpload.QueryParameters = string.Format("User={0}", Session["UserId"].ToString());
                    }
                }
            }
        }
        /// <summary>
        /// Mb--Tagging Images
        /// </summary>
        /// <param name="userId"></param>
        private void GetTagImages(string userId)
        {
            try
            {
                var ds = (DataSet)oUserUploadsBll.GetTagImages(userId);
                if (ds != null && ds.Tables[0].Rows.Count != 0)
                {
                    hdn_Tagging.Value = "";
                    Cache["ods"] = ds;
                    dl_tagging.DataSource = ds;
                    dl_tagging.DataBind();
                    div_FlashUpload.Style.Value = "display:none;";
                    div_FlashReturn.Style.Value = "display:block;overflow:scroll";
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Mb--ItemDataBound
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dl_tagging_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                int userId = Convert.ToInt32(Session["UserId"]);
                int index = e.Item.ItemIndex;
                var ds = (DataSet)Cache["ods"];
                var img_Tagging = (HtmlImage)e.Item.FindControl("img_Tagging");
                img_Tagging.Src = "storage/" + userId + "/" + ds.Tables[0].Rows[index]["UpFileName"].ToString();
                hdn_Tagging.Value += ds.Tables[0].Rows[index]["UpListId"].ToString() + ",";
            }
        }
        /// <summary>
        /// Mb--Video Save Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnVideosave_Click(object sender, EventArgs e)
        {
            try
            {
                int res = oUserUploadsBll.SaveVideo(oUserUploadsMdl);
                if (res > 0)
                {
                    Page.RegisterStartupScript("Success", "<script type=text/javascript>alert('Video Uploaded Successfully');</script>");
                    div_VideoReturn.Style.Value = "display:none";
                    div_VideoUpload.Style.Value = "display:";
                }
                else
                    lbl_msg.Text = "Error occured,please upload again";
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
 
But this js works only if i put a breakpoint in the firebug for this function or in chrome check scripts there also if i put breakpoint alert is showing and it works but... if i just try and click the button it does not show the alert and page redirect is also not happening.... So can u please help me solve this error as i am unable to find any solution for this... Thanking You in advance!!
Posted 20-Sep-12 23:07pm
Edited 21-Sep-12 3:52am
v2
Comments
Mohibur Rashid at 21-Sep-12 4:29am
   
what is the value of arrTxtMM.length?
Shruthi.BT at 21-Sep-12 5:25am
   
the length of the values in hidden field.... but no problem there ... the entire function is itself not called on onclick.... what might be wrong??
Tadit Dash at 21-Sep-12 6:31am
   
Can u post the .cs file codings ?
Shruthi.BT at 21-Sep-12 7:29am
   
for this button onclick there is no .cs coding.. it has only js ... then alerts if i put they are working correctly till the $.getJSON(url,function(json) but after this any alert i put its not working... what might be wrong??
Tadit Dash at 21-Sep-12 7:40am
   
Actually I want to debug at my local, that's why I was asking you to post the codings. Please post whatever you have written in .cs file by clicking on "Improve Question" link.
Don't forget to post the whole .aspx coding also.
I will try to help you for sure.
Thanks...
Shruthi.BT at 21-Sep-12 8:53am
   
its updated... please try to help.. but the code behind has nothing to do with the js problem it is with json and handler.. so shall i post handler page... code behind??
Tadit Dash at 21-Sep-12 9:12am
   
Oh yes...
 
One more question...
Are you sure of the URL ('Handler/newExifDetails.ashx?Id=' + txtMM + '&Location=' + checkLocation + '';)?
And are you getting the values for txtMM and checkLocation . Please check for them using alert boxes.
Shruthi.BT at 21-Sep-12 9:35am
   
Handler code:
 
<pre>using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Serialization;
using System.Collections.ObjectModel;
using ClassLib_BLL;
using System.IO;
using System.Web.UI;
using System.Net;
using System.Collections.Generic;
 
namespace QlixooWeb.handler
{
///
/// Summary description for $codebehindclassname$
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 
public class UserUploadsDTO
{
private int _res;
public int res { get { return _res; } set { _res = value; } }
}
 
public class newExifDetails : IHttpHandler
{
public static readonly UserUploadsBLL oUserUploadsBll = new UserUploadsBLL();
string[] splitQueryStr, arId, arLocation;
public string Id1, Location1;
 
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
Collection collection = new Collection();
UserUploadsDTO dto;
string RId = context.Request.QueryString["Id"].ToString();
string RLocation = context.Request.QueryString["Location"].ToString();
//string json = new StreamReader(context.Request.InputStream).ReadToEnd();//Location = Bangalore%2C+Karnataka%2C+India%3AChittur%2C+Kerala%2C+India %3A & Id=4%2C94
//splitQueryStr = json.Split('&');
//Location1 = splitQueryStr[0];
//Id1 = splitQueryStr[1];
//string Location = RLocation.Substring(Location1.IndexOf('=', 0) + 1);
string Location = RLocation;
//Location = Location.Replace("%2C+", ",");
//Location = Location.Replace("%3A", ":");
//Location = Location.Replace("+", " ");
Location = Location.TrimEnd(':');
arLocation = Location.Split(':');
string Id = RId;
//string Id = RId.Substring(Id1.IndexOf('=', 0) + 1);
//Id = Id.Replace("%2C", ",");
arId = Id.Split(',');
int res = 0;
for (int i = 0; i < arId.Length; i++)
{
int UpId = Convert.ToInt32(arId[i]);
Coordinate coordinate = Geocode.GetCoordinates(arLocation[i]);
decimal latitude = coordinate.Latitude;
decimal longitude = coordinate.Longitude;
res = oUserUploadsBll.TaggingImages(latitude, longitude, UpId);
}
if (res > 0)
{
dto = new UserUploadsDTO();
dto.res = res;
collection.Add(dto);
}
//context.Response.Redirect("~/UserUploads.aspx");
//context.Response.Write(res);
else
context.Response.Write("false");
JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsonString = serializer.Serialize(collection);
context.Response.Write(jsonString);
 
}
public interface ISpatialCoordinate
{
decimal Latitude { get; set; }
decimal Longitude { get; set; }
}
///
/// Coordiate structure. Holds Latitude and Longitude.
///

public struct Coordinate : ISpatialCoordinate
{
private decimal _latitude;
private decimal _longitude;
public Coordinate(decimal latitude, decimal longitude)
{
_latitude = latitude;
_longitude = longitude;
}
#region ISpatialCoordinate Members
public decimal Latitude
{
get { return _latitude; }
Shruthi.BT at 21-Sep-12 9:40am
   
}
public decimal Longitude
{
get { return _longitude; }
set { this._longitude = value; }
}
#endregion
}
public class Geocode
{
private const string _googleUri = "http://maps.google.com/maps/geo?q=";
private const string _googleKey = "AIzaSyB4UgLW37a1jhxnnz5J27KPNaHIDmapSYk";
private const string _outputType = "csv"; // Available options: csv, xml, kml, json
private static Uri GetGeocodeUri(string address)
{
address = HttpUtility.UrlEncode(address);
return new Uri(String.Format("{0}{1}&output={2}&key={3}", _googleUri, address, _outputType, _googleKey));
}
public static Coordinate GetCoordinates(string address)
{
WebClient client = new WebClient();
Uri uri = GetGeocodeUri(address);
/* The first number is the status code,
* the second is the accuracy,
* the third is the latitude,
* the fourth one is the longitude.
*/
string[] geocodeInfo = client.DownloadString(uri).Split(',');
return new Coordinate(Convert.ToDecimal(geocodeInfo[2]), Convert.ToDecimal(geocodeInfo[3]));
}
}
 
public bool IsReusable
{
get
{
return false;
}
}
}
}
Shruthi.BT at 21-Sep-12 9:41am
   
remaining code i have pasted in next comment as all was not pasted in the first one...
compninja25 at 21-Sep-12 20:10pm
   
Just for giggles, do you notice any difference if you move the script up to the head tag? Have you tried removing the google maps script reference to see if that helps? I remember having an issue like this a long time ago and think it might of had something to do with sequence which the scripts were being loaded...but I can't remember for sure.
compninja25 at 21-Sep-12 20:18pm
   
Did a quick google search and other similar issues seem to all point to something with the ajax call. Check this out: http://stackoverflow.com/questions/6558605/javascript-is-executed-only-with-a-breakpoint
Shruthi.BT at 24-Sep-12 5:50am
   
yes... i have tried pasting in js in different places in the sense.. i have changed the position of js... and tried and also the js code i modified and called the handler by using a ajax jquery ... still there is some problem... the success function is not showing...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 275
2 Sergey Alexandrovich Kryukov 187
3 Afzaal Ahmad Zeeshan 154
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100