Popup Control Extender

Last post 09-01-2008 5:09 AM by rasmusbang. 7 replies.

Sort Posts:

  • Popup Control Extender

    08-27-2008, 7:49 AM
    • Member
      8 point Member
    • rasmusbang
    • Member since 08-11-2008, 3:22 AM
    • Posts 37

     Hi,

     I am trying to get a popup panel to show, when clicking a linkbutton. I need to show a popup where I can alter the value of the linkbutton text, and send it to the database as an update. However, I am having trouble getting the panel to show. I create all my web controls dynamically, so maybe this is the problem.I use a Table for organazing the controls. This Table Control is then itself added to a Panel which is defined in the aspx file. Disregarding this, perhaps the code can help clarify the problem.

    My code:

                    LinkButton dateLbl = new LinkButton ();
                    dateLbl.Text = "Test";
                    dateLbl.ID = "dateLbl1";
                    myTableCell dateCell = new myTableCell(dateLbl);
                    AjaxControlToolkit.PopupControlExtender datePopup = new AjaxControlToolkit.PopupControlExtender();
                    Panel datePanel = new Panel();
                    datePanel.ID = "datePanel1";
                    datePanel.Controls.Add(new myLabel("This is the Panel"));
                    datePopup.TargetControlID = "dateLbl1";
                    datePopup.PopupControlID = "datePanel1";

    As far as I understand, the panel should then be shown, when the link button is clicked?

    Hope for your help, and apologize if this topic is already answered elsewhere (haven't been able to find it).

    Rasmus

  • Re: Popup Control Extender

    08-27-2008, 1:29 PM

    rasmusbang,

    Are you adding datePopup to your form?  It may be in part of the code you haven't displayed.

    If you already are, then you need to be sure you are adding these controls back into the Control Tree for the Page on _every_ partial and full postback, otherwise they will get lost, even if it continues to display in an update panel on the client.

    You've probably already read this, or know what it is talking about, but in case you haven't, here's a good article on adding dynamic controls: http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Popup Control Extender

    08-27-2008, 3:12 PM
    • Participant
      1,274 point Participant
    • atanu.podder
    • Member since 08-20-2008, 11:40 AM
    • Bangalore
    • Posts 191

    Here is my recomendation,

    1. Have popup extender and popup panel statically in the page.

    2. Put the contents in the popup panel dynamically.

    3. Instead on setting the target control id dynamically, use attach javascript onlcick attribute to the control, which you want to act as target control.

    Let me know if you need any further assistance on this.

    Thanks,

    Atanu   

    Thanks,
    Atanu, Symphony Services

    P.S. Dont forget to mark this as answer, if you have got resolution to your problem from this post.
  • Re: Popup Control Extender

    08-28-2008, 3:25 AM
    • Member
      8 point Member
    • rasmusbang
    • Member since 08-11-2008, 3:22 AM
    • Posts 37

     Hi,

    I will be needing some help in the third point. I am not that big a javascript coder, and I have kept it on safe distance. How do I use onclick to set the target control? I guess I need to do it in the .cs file dynamically or how?

    Rasmus

  • Re: Popup Control Extender

    08-28-2008, 5:18 AM
    • Member
      8 point Member
    • rasmusbang
    • Member since 08-11-2008, 3:22 AM
    • Posts 37

    I have now gone for the modal Popup instead - as I found the Ajax toolkit video on the topic. Now it is displaying. But I can not get it to act as the "front". I would like for the page to inactive, such that the user can only interact with the panel displayed by the popup. How can I do so?

     

  • Re: Popup Control Extender

    08-29-2008, 2:53 AM
    • Member
      8 point Member
    • rasmusbang
    • Member since 08-11-2008, 3:22 AM
    • Posts 37

     Hi all,

     Just an update to the issue, which I have still not solved.

    I add LinkButtons dynamically, and keep a ModalPopupExtender and a Panel in the .aspx file. I have tried to set the ModalPopups TargetControlId to that of a LinkButton using the Click event on the LinkButton. However, this causes the LinkButton having to be pushed twice in order for the Popup to display. Anyone know what I am doing wrong?

    Is it simply because I (in some sense) is setting the TargetControlId value at "the wrong point" in execution. At the time of the click the LinkBotton is not the TargetControl obviously.

    Hope some one can help me in this issue.

    Rasmus

  • Re: Popup Control Extender

    08-29-2008, 2:03 PM
    Answer
    • Participant
      1,274 point Participant
    • atanu.podder
    • Member since 08-20-2008, 11:40 AM
    • Bangalore
    • Posts 191

    Your scenario is pretty straight forward, and i strongly feel we can resolve it quicker if you can share your code. I can fix those issues and repost the code.

    Secondly, incase you want try certain things at your end, here are my suggestions:

    1. You need to puch the button twice bcos, you setting  ModalPopup's TargetControlId to the a LinkButton using the Click event on the LinkButton. So, what happens is, on the first click its just gettng assigned, and from the second click it starts popping up. So, on the click event, instead of just setting the target control id, invoke show() method on the modal popup. (ex. ModalPopup1.Show() ).

    2. Alternatively you can attach onclick attribute to the link button like linkButton1.Attributes.Add("MyJavaScriptFunction", "onclick"). And you can have the javascript function definition as <script type="text/javascript">function MyJavaScriptFunction(){ $find('ModalPopup1').show()}</script>

     

    Let me know if you need any further assistence on this.

    Thaks,

    Atanu 

     

    Thanks,
    Atanu, Symphony Services

    P.S. Dont forget to mark this as answer, if you have got resolution to your problem from this post.
  • Re: Popup Control Extender

    09-01-2008, 5:09 AM
    • Member
      8 point Member
    • rasmusbang
    • Member since 08-11-2008, 3:22 AM
    • Posts 37

     Hi again,

     Got it working - thank you very much.
    A new issue has emerged now. Because I a using quite a lot of LinkButtons, I need to be able to alter the Panel which the ModalPopupExtender uses as PopupControl. I have tried to add TextBoxes and Buttons to the Panel just before calling Show() on the ModalPopup, but the Panel is exactly as it is when declared in the .aspx file.

    I guess it is due to some PostBack, and the fact that the Panel is not changed in the Page_Load function?

     My Click event:

        void date_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            myLabel lbl = new myLabel("testLabel");
            Panel2.Controls.Add(lbl);
            Panel2.Height = 200;

            ModalPopupExtender1.TargetControlID = lnk.ID;
            ModalPopupExtender1.Show();
       
        }

    Regards,
    Rasmus

Page 1 of 1 (8 items)