Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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="/KB/answers/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
Updated 21-Sep-12 2:52am
v2
Comments
Mohibur Rashid 21-Sep-12 4:29am    
what is the value of arrTxtMM.length?
Shruthi.BT 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??
Can u post the .cs file codings ?
Shruthi.BT 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??
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...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900