Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my Composite control I placed a button. Which when clicked, a popup will be shown. In the popup there will be another button which when clicked will show text in TextBox and more... I can show popup but when the button is clicked in the popup, the popup vanishes away. Again when I click the first button, the popup is not shown. So I want to surround controls in the popup with UpdatePanel so that no postback problem occurs. But truly I messed up. Can't implement UpdatePanel in Composite control till now. Truly I used Google too much. Please suggest me a solution with full codes.

public class MyCompositeControl : CompositeControl, INamingContainer

    {
        
        
        private ImageButton cmdResult = new ImageButton();
        
        private LiteralControl first = new LiteralControl(string.Format("<div id=\"div_to_popup\" style=\"display:none; background-color:White;color:Black;width:430px;height:300px;\"><div id=\"div_to_popup2\" style=\"border:3px solid Gray;height:100%;\">"));

        private TextBox text1 = new TextBox();
        private TextBox text2 = new TextBox();
        private DropDownList ddlist1 = new DropDownList();        
        private Label lblResult = new Label();
        private LiteralControl lc = new LiteralControl("<br>");
        private Button Button = new Button();
        LiteralControl sec = new LiteralControl("</div>");
                    
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? "[" + this.ID + "]" : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }       
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            
            //ScriptManager sm = ScriptManager.GetCurrent(Page);

            Button.Text = "kick button";                               

            text1.Height = Unit.Pixel(25);
            text1.Width = Unit.Pixel(70);
            text1.Text = "0";

            text2.Height = Unit.Pixel(25);
            text2.Width = Unit.Pixel(70);
            text2.Text = "0";

            ddlist1.Height = Unit.Pixel(25);
            ddlist1.Width = Unit.Pixel(40);

            ddlist1.Items.Add("+");
            ddlist1.Items.Add("-");
            ddlist1.Items.Add("*");
            ddlist1.Items.Add("/");

            cmdResult.Height = Unit.Pixel(25);
            cmdResult.Width = Unit.Pixel(50);
            cmdResult.AlternateText = "Result";

            lblResult.Height = Unit.Pixel(25);
            lblResult.Width = Unit.Pixel(200);

            DotNetNuke.Entities.Modules.PortalModuleBase u = new PortalModuleBase();
            lblResult.Text = "result";// u.UserId.ToString(); ;

            
            Button.Click += new EventHandler(Button_Click);
            cmdResult.Click += new ImageClickEventHandler(cmdResult_Click);

            Controller control = new Controller();
            DateTime dt = DateTime.Now.AddHours(-24);
            
        }        

        protected override void OnPreRender(EventArgs e)
        {           
            StringBuilder sb = new StringBuilder();           
            sb.AppendFormat("<link rel=\"stylesheet\" href=\"general.css \" type=\"text/css\"  />{0}", "\r\n");           
            sb.Append("<script type=\"text/javascript\">");
            sb.Append("(function (a) { a.fn.bPopup = function (h, j) { function s() { b.css({ left: !o.follow[1] && k ? d : c.scrollLeft() + d, position: \"absolute\", top: !o.follow[0] && l ? e : c.scrollTop() + e, \"z-index\": o.zIndex }).appendTo(o.appendTo).hide(1, function () { a.isFunction(o.onOpen) && o.onOpen.call(b); if (o.loadUrl != null) switch (o.contentContainer = o.contentContainer == null ? b : a(o.contentContainer), o.content) { case \"iframe\": a('<iframe scrolling=\"no\" frameborder=\"0\"></iframe>').attr(\"src\", o.loadUrl).appendTo(o.contentContainer); break; default: o.contentContainer.load(o.loadUrl) } }).fadeIn(o.fadeSpeed, function () { a.isFunction(j) && j() }); t() } function i() { o.modal && a(\"#bModal\").fadeOut(o.fadeSpeed, function () { a(\"#bModal\").remove() }); b.fadeOut(o.fadeSpeed, function () { o.loadUrl != null && o.contentContainer.empty() }); o.scrollBar || a(\"html\").css(\"overflow\", \"auto\"); a(\".\" + o.closeClass).die(\"click\"); a(\"#bModal\").die(\"click\"); c.unbind(\"keydown.bPopup\"); f.unbind(\".bPopup\"); b.data(\"bPopup\", null); a.isFunction(o.onClose) && setTimeout(function () { o.onClose.call(b) }, o.fadeSpeed); return !1 } function u() { if (n || v) { var a = [c.height(), c.width()]; return { \"background-color\": o.modalColor, height: a[0], left: m(), opacity: 0, position: \"absolute\", top: 0, width: a[1], \"z-index\": o.zIndex - 1} } else return { \"background-color\": o.modalColor, height: \"100%\", left: 0, opacity: 0, position: \"fixed\", top: 0, width: \"100%\", \"z-index\": o.zIndex - 1} } function t() { a(\".\" + o.closeClass).live(\"click\", i); o.modalClose && a(\"#bModal\").live(\"click\", i).css(\"cursor\", \"pointer\"); (o.follow[0] || o.follow[1]) && f.bind(\"scroll.bPopup\", function () { b.stop().animate({ left: o.follow[1] ? c.scrollLeft() + d : d, top: o.follow[0] ? c.scrollTop() + e : e }, o.followSpeed) }).bind(\"resize.bPopup\", function () { if (o.modal && n) { var a = [c.height(), c.width()]; p.css({ height: a[0], width: a[1], left: m() }) } g = q(b, o.amsl); o.follow[0] && (e = l ? e : c.scrollTop() + g[0]); o.follow[1] && (d = k ? d : c.scrollLeft() + g[1]); b.stop().animate({ left: d, top: e }, o.followSpeed) }); o.escClose && c.bind(\"keydown.bPopup\", function (a) { a.which == 27 && i() }) } function m() { return f.width() < a(\"body\").width() ? 0 : (a(\"body\").width() - f.width()) / 2 } function q(a, b) { var c = (f.height() - a.outerHeight(!0)) / 2 - b, d = (f.width() - a.outerWidth(!0)) / 2 + m(); return [c < 20 ? 20 : c, d] } a.isFunction(h) && (j = h, h = null); o = a.extend({}, a.fn.bPopup.defaults, h); o.scrollBar || a(\"html\").css(\"overflow\", \"hidden\"); var b = a(this), p = a('<div id=\"bModal\"></div>'), c = a(document), f = a(window), g = q(b, o.amsl), l = o.position[0] != \"auto\", k = o.position[1] != \"auto\", e = l ? o.position[0] : g[0], d = k ? o.position[1] : g[1], r = navigator.userAgent.toLowerCase(), v = r.indexOf(\"iphone\") != -1, n = /msie 6/i.test(r) && typeof window.XMLHttpRequest != \"object\"; this.close = function () { o = b.data(\"bPopup\"); i() }; return this.each(function () { b.data(\"bPopup\") || (o.modal && p.css(u()).appendTo(o.appendTo).animate({ opacity: o.opacity }, o.fadeSpeed), b.data(\"bPopup\", o), s()) }) }; a.fn.bPopup.defaults = { amsl: 50, appendTo: \"body\", closeClass: \"bClose\", content: \"ajax\", contentContainer: null, escClose: !0, fadeSpeed: 250, follow: [!0, !0], followSpeed: 500, loadUrl: null, modal: !0, modalClose: !0, modalColor: \"#000\", onClose: null, onOpen: null, opacity: 0.7, position: [\"auto\", \"auto\"], scrollBar: !0, zIndex: 9999} })(jQuery);");
            sb.Append("</script>\r\n");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Cp_Detail_Script", sb.ToString());            
        }
        /// <summary>
        /// This CreateChildControls should be used to write code for
        /// creating our composite controls
        /// </summary>
        protected override void CreateChildControls()
        {
            Controls.Add(cmdResult);
            Controls.Add(first);
            Controls.Add(text1);
            Controls.Add(ddlist1);
            Controls.Add(text2);
            Controls.Add(lc);
            Controls.Add(lblResult);
            Controls.Add(Button);
            Controls.Add(sec);

        }        
        private string getjQueryCode(string jsCodetoRun)
        {
            StringBuilder sb = new StringBuilder();
             sb.AppendLine("function pageLoad() {");            
            sb.AppendLine(jsCodetoRun);
            sb.AppendLine(" };");            
            return sb.ToString();
        }
        private void runjQueryCode(string jsCodetoRun)
        {

            ScriptManager requestSM = ScriptManager.GetCurrent(Page);
             if (requestSM != null && requestSM.IsInAsyncPostBack)
             {
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), true);                
               // ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), true);
             }
             else
             {
            Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), true);
             }
        }
        private void cmdResult_Click(object sender, EventArgs e)
        {
            Label lblResult = (Label)Controls[6];
            try
            {

                TextBox text1 = (TextBox)Controls[2];
                DropDownList ddBox = (DropDownList)Controls[3];
                TextBox text2 = (TextBox)Controls[4];

                this.EnsureChildControls();
                switch (ddBox.SelectedValue)//switch ( ddBox.SelectedValue)
                {

                    case "+":
                        lblResult.Text = Convert.ToString(Convert.ToInt32(text1.Text) + Convert.ToInt32(text2.Text));
                        break;

                    case "-":
                        lblResult.Text = Convert.ToString(Convert.ToInt32(text1.Text) - Convert.ToInt32(text2.Text));
                        break;

                    case "*":
                        lblResult.Text = Convert.ToString(Convert.ToInt32(text1.Text) * Convert.ToInt32(text2.Text));
                        break;

                    case "/":
                        lblResult.Text = Convert.ToString(Convert.ToInt32(text1.Text) / Convert.ToInt32(text2.Text));
                        break;

                }

                runjQueryCode("$('#div_to_popup').bPopup({ appendTo: 'form', zIndex: 2, closeClass: 'clickclose',modalColor: 'White', modalClose: false, scrollBar: true });return false;");
                
            }
            catch (Exception eVal)
            {
                lblResult.Text = eVal.ToString();
            }

        }
        protected override void RenderContents(HtmlTextWriter writer)
        {
           // up.RenderControl(writer);
            cmdResult.RenderControl(writer);
            first.RenderControl(writer);
            text1.RenderControl(writer);
            ddlist1.RenderControl(writer);
            text2.RenderControl(writer);

            lc.RenderControl(writer);
            lblResult.RenderControl(writer);
            Button.RenderControl(writer);
            sec.RenderControl(writer);
        }

        private void  Button_Click(object sender, EventArgs e)
        {
            TextBox text1 = (TextBox)Controls[2];           
            text1.Text = "testsucces";           
        }
    }
Posted
Updated 26-Aug-11 0:08am
v3
Comments
mridul samadder 21-Aug-11 11:38am    
any guys plz help me

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



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