linkbutton单击jquery模式弹出窗口

时间:2013-11-22 06:30:12

标签: javascript jquery asp.net repeater

我有一个转发器,并且在该转发器的项目模板中我有一个按钮,当我单击此按钮时,它在jquery模式弹出窗口中打开另一个view.aspx页面,到现在它工作正常,但是当我单击一个链接按钮在view.aspx页面(以模态弹出窗口打开)然后view.aspx在正常模式下自动打开(不是在模态弹出窗口中)

请帮帮我,谢谢你

图片enter image description here

在上图中,当我点击此链接按钮时,edukating(9)是一个链接按钮,它就是这样发生的

enter image description here

我使用了以下代码

转发器中的代码(仅用于弹出窗口的代码):

<script type="text/javascript">
function CollectModalPopUp() {
        $(document).ready(function () {
            var mydiv = $('#mydiv');
            mydiv.dialog({ autoOpen: false });
            // Load the content using AJAX
            mydiv.load('ViewNoteTest.aspx');
            // Open the dialog
            mydiv.dialog('open');

            return false;
        });
    }
</script>

 <div id="mydiv">

 </div>

转发器按钮点击事件中的代码

objBalItem = new BalItem();
                Session.Remove("dtAllTags");
                Session.Remove("dtAllAddedTags");
                int ItemId = Convert.ToInt32(e.CommandArgument.ToString().Split(',')[0].ToString());
                //string Url = e.CommandArgument.ToString().Split(',')[2].ToString();
                LstItemSuggestTags = new List<BeSuggestedTag>();
                LstItemSuggestTags = objBalItem.GetItemTagSuggestions(ItemId);
                Session["LstItemSuggestTags "] = LstItemSuggestTags;
                Session["CommandArgument"] = e.CommandArgument.ToString();
                Session["UserInContext"] = UserInContext;
                string script = "<script type=\"text/javascript\"> CollectModalPopUp(); </script>";
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, false);

ViewPageTest.aspx中的代码

 protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] != null)
            {
                UserObj = new UserInfo();
                UserObj = (UserInfo)Session["UserInfo"];
                UserId = Convert.ToInt64(UserObj.Id);
            }

            if (Session["LstItemSuggestTags "] != null && Session["CommandArgument"] != null)
            {

                if (!IsPostBack)
                {
                    LstItemSuggestTags = Session["LstItemSuggestTags "] as List<BeSuggestedTag>;
                    foreach (BeSuggestedTag ItemSuggestTags in LstItemSuggestTags)
                    {
                        if (!dtAllTags.Columns.Contains("TagId"))
                        {
                            dtAllTags.Columns.Add("TagId");
                        }
                        if (!dtAllTags.Columns.Contains("TagName"))
                        {
                            dtAllTags.Columns.Add("TagName");
                        }
                        drAllTags = dtAllTags.NewRow();
                        drAllTags["TagId"] = ItemSuggestTags.TagId.ToString();
                        drAllTags["TagName"] = ItemSuggestTags.TagName.ToString();
                        dtAllTags.Rows.Add(drAllTags);


                    }
                    Session["dtAllTags"] = dtAllTags;
                    //GenerateSuggestedTags();
                    //AddTags();
                }
                string CommandArgument = Session["CommandArgument"].ToString();
                ItemId = Convert.ToInt64(CommandArgument.Split(',')[0].ToString());
                lblTitleText.Text = CommandArgument.Split(',')[1].ToString();
                lnkbtnUrl.Text = CommandArgument.Split(',')[2].ToString();
                lnkbtnUrl.PostBackUrl = CommandArgument.Split(',')[2].ToString();
                lblDescriptionText.Text = CommandArgument.Split(',')[3].ToString();
                GenerateSuggestedTags();
                AddTags();
            }

        }

        protected void GenerateSuggestedTags()
        {
            if (Session["dtAllTags"] != null)
            {
                dtAllTags = Session["dtAllTags"] as DataTable;
                pnlPopupSuggestedTags.Controls.Clear();
                foreach (DataRow dr in dtAllTags.Rows)
                {
                    Panel pnlRelateTags = new Panel();
                    pnlRelateTags.ID = "InnerRelatedTagspnl_" + dr["TagId"].ToString();
                    LinkButton lnkraltedTag = new LinkButton();
                    lnkraltedTag.ID = "lnkraltedTag_" + dr["TagId"].ToString();
                    ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(lnkraltedTag);
                    // pnlRelateTags.CssClass = "RelatedTags";
                    pnlRelateTags.ToolTip = "Include Tag";
                    pnlRelateTags.Style.Add("overflow", "hidden");
                    lnkraltedTag.Text = (dr["TagName"].ToString().Length > 15 ? dr["TagName"].ToString().Substring(0, 15) : dr["TagName"].ToString());
                    lnkraltedTag.CommandArgument = dr["TagId"].ToString() + "," + dr["TagName"].ToString();
                    lnkraltedTag.Command += new CommandEventHandler(lnkraltedTag_Command);
                    lnkraltedTag.CssClass = "RelatedTags";
                    lnkraltedTag.EnableViewState = true;
                    lnkraltedTag.Style.Add("word-break", "break-word");
                    pnlRelateTags.Controls.Add(lnkraltedTag);
                    pnlPopupSuggestedTags.Controls.Add(pnlRelateTags);
                }
            }
        }

        protected void lnkraltedTag_Command(object sender, CommandEventArgs e)
        {
            AddTagToPanel(e.CommandArgument.ToString());
        }

        private void AddTagToPanel(string commandArgument)
        {
            Int64 tagId = Convert.ToInt64(commandArgument.Split(',')[0].ToString());
            string tagName = commandArgument.Split(',')[1].ToString();
            if (Session["dtAllAddedTags"] != null)
            {
                dtAddedTags = Session["dtAllAddedTags"] as DataTable;
            }
            if (!dtAddedTags.Columns.Contains("TagId"))
            {
                dtAddedTags.Columns.Add("TagId");
            }
            if (!dtAddedTags.Columns.Contains("TagName"))
            {
                dtAddedTags.Columns.Add("TagName");
            }
            drAddedTags = dtAddedTags.NewRow();
            drAddedTags["TagId"] = tagId;
            drAddedTags["TagName"] = tagName;
            dtAddedTags.Rows.Add(drAddedTags);
            dtAddedTags = RemoveDuplicateRows(dtAddedTags, "TagId");
            //foreach (DataRow dr in dtAddedTags.Rows)
            //{
            //    Panel pnlTag = pnlPopupSuggestedTags.FindControl("InnerRelatedTagspnl_" + dr["TagId"].ToString()) as Panel;
            //    pnlPopupSuggestedTags.Controls.Remove(pnlTag);
            //}
            Session["dtAllAddedTags"] = dtAddedTags;
           AddTags();
            dtAllTags = Session["dtAllTags"] as DataTable;
            foreach (DataRow drOuter in dtAddedTags.Rows)
            {
                for (int i = dtAllTags.Rows.Count - 1; i >= 0; i--)
                {
                    DataRow drInner = dtAllTags.Rows[i];
                    if (drOuter["TagId"].ToString() == drInner["TagId"].ToString())
                    {
                        drInner.Delete();
                    }
                }
            }
            Session["dtAllTags"] = dtAllTags;
            GenerateSuggestedTags();
        }

        public void AddTags()
        {
            if (Session["dtAllAddedTags"] != null)
            {
                dtAddedTags = Session["dtAllAddedTags"] as DataTable;
                pnlPopupTags.Controls.Clear();
                foreach (DataRow row in dtAddedTags.Rows)
                {
                    Panel pnl = new Panel();
                    pnl.ID = "Innerpnl_" + row["TagId"].ToString();
                    LinkButton lnkTag = new LinkButton();
                    lnkTag.ID = "lnkTag" + row["TagId"].ToString();
                    pnl.CssClass = "tags";
                    lnkTag.Text = row["TagName"].ToString();
                    lnkTag.CommandArgument = row["TagId"].ToString() + "," + row["TagName"].ToString();
                    lnkTag.Command += new CommandEventHandler(lnkTag_Command);
                    ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(lnkTag);
                    pnl.Controls.Add(lnkTag);
                    pnlPopupTags.Controls.Add(pnl);
                }
            }
        }

        public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
        {
            Hashtable hTable = new Hashtable();
            ArrayList duplicateList = new ArrayList();

            //Add list of all the unique item value to hashtable, which stores combination of key, value pair.
            //And add duplicate item value in arraylist.
            foreach (DataRow drow in dTable.Rows)
            {
                if (hTable.Contains(drow[colName]))
                    duplicateList.Add(drow);
                else
                    hTable.Add(drow[colName], string.Empty);
            }

            //Removing a list of duplicate items from datatable.
            foreach (DataRow dRow in duplicateList)
                dTable.Rows.Remove(dRow);

            //Datatable which contains unique records will be return as output.
            return dTable;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
        }

        protected void lnkTag_Command(object sender, CommandEventArgs e)
        {
            DeleteTagFromPanel(e.CommandArgument.ToString());
        }

        protected void DeleteTagFromPanel(string commandArgument)
        {
            dtAllTags = Session["dtAllTags"] as DataTable;
            dtAddedTags = Session["dtAllAddedTags"] as DataTable;
            //foreach (DataRow dr in dtAddedTags.Rows)
            //{
            //    Panel pnlTag = pnlPopupTags.FindControl("Innerpnl_" + dr["TagId"].ToString()) as Panel;
            //    pnlPopupTags.Controls.Remove(pnlTag);
            //}

            Int64 tagId = Convert.ToInt64(commandArgument.Split(',')[0].ToString());
            string tagName = commandArgument.Split(',')[1].ToString();
            if (Session["dtAllTags"] != null)
            {
                dtAllTags = Session["dtAllTags"] as DataTable;
            }
            if (!dtAllTags.Columns.Contains("TagId"))
            {
                dtAllTags.Columns.Add("TagId");
            }
            if (!dtAllTags.Columns.Contains("TagName"))
            {
                dtAllTags.Columns.Add("TagName");
            }
            drAllTags = dtAllTags.NewRow();
            drAllTags["TagId"] = tagId;
            drAllTags["TagName"] = tagName;
            dtAllTags.Rows.Add(drAllTags);
            foreach (DataRow drOuter in dtAllTags.Rows)
            {
                for (int i = dtAddedTags.Rows.Count - 1; i >= 0; i--)
                {
                    DataRow drInner = dtAddedTags.Rows[i];
                    if (drOuter["TagId"].ToString() == drInner["TagId"].ToString())
                    {
                        drInner.Delete();
                    }
                }
            }
            Session["dtAllTags"] = dtAllTags;
            Session["dtAllAddedTags"] = dtAddedTags;
            AddTags();
            GenerateSuggestedTags();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Int64? UserInContext = Session["UserInContext"] as Int64?;

            dtAddedTags = Session["dtAllAddedTags"] as DataTable;
            if (!dtTagId.Columns.Contains("TagId"))
            {
                dtTagId.Columns.Add("TagId");
            }
            if (dtTagId.Rows.Count > 0)
            {
                foreach (DataRow dr in dtAddedTags.Rows)
                {
                    drTagId = dtTagId.NewRow();
                    drTagId["TagId"] = dr["TagId"].ToString();
                    dtTagId.Rows.Add(drTagId);
                }
            }
            objBalItem = new BalItem();
           Int32 flag= objBalItem.CollectItem(ItemId, UserId, UserInContext, dtTagId);
           if (flag == 0)
           {

               ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "ModalPopUpWithOKbutton();", true);
               //string script = "<script type=\"text/javascript\"> HideModal(); </script>";
               //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "HideModal", script);
           }
           else if(flag == 1)
           {
               //pmsg.InnerText = "Problem in collecting Item";
               string script = "<script type=\"text/javascript\"> ModalPopUpWithOKbutton(); </script>";
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ModalPopUpWithOKbutton", script);
           }
        }

1 个答案:

答案 0 :(得分:0)

有关正确使用document ready look here.

的信息

您应该从$(document).ready()函数中删除CollectModalPopUp,因为它会阻止代码运行。我不确定这是不是问题,但它将是其中之一。

function CollectModalPopUp() {
  var mydiv = $('#mydiv');
  mydiv.dialog({ autoOpen: false });
  // Load the content using AJAX
  mydiv.load('ViewNoteTest.aspx');
  // Open the dialog
  mydiv.dialog('open');
  return false;
}