Postback problem in ModalPopupExtender with LinkButton

Last post 02-10-2009 12:34 PM by felipecsl. 11 replies.

Sort Posts:

  • Postback problem in ModalPopupExtender with LinkButton

    02-03-2009, 9:46 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    Hi all,
    I've given up trying to find a solution to this. I have a custom web control with a TreeView and a dynamic ul list built based on the selected node in the tree. So far so good.
    However, I need to be able to select the li item from the list and call the code behind. I used LinkButton for that, but it is reloading the entire page when clicked. My custom control is inside an UpdatePanel. The SelectedNodeChanged event in the TreeView works fine, but the LinkButton refuses to work as expected and reloads the entire page :(

    Here is the code that creates the link buttons:

    LinkButton linkFileBtn = new LinkButton();
    linkFileBtn.Text = file.Name;
    linkFileBtn.Click += new EventHandler(SelectedFileChanged);
    linkFileBtn.Attributes.Add("runat", "server");
    linkFileBtn.CssClass = "fileentry";

    HtmlImage fileImage = new HtmlImage();
    fileImage.Src = "images/image.png";
    fileImage.Attributes.Add("class", "fileicon");

    HtmlGenericControl liList = new HtmlGenericControl("li");
    liList.Attributes.Add("class", "fileentry");
    liList.Attributes.Add("onclick", "SwitchClass(this)");

    liList.Controls.Add(fileImage);
    liList.Controls.Add(linkFileBtn);
    ulFileList.Controls.Add(liList);

    What am I doing wrong?!? Please, any help would be greatly appreciated!

    Thanks in advance,
    Felipe
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-03-2009, 10:21 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    Update: I removed everything from the Custom Control and just left a LinkButton. The problem still happens.
    With a regular input Button, this does not happen.
    If I use the LinkButton alone inside the UpdatePanel (not inside a custom web control) everything works fine.

    Suggestions?

    Thanks
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-04-2009, 8:40 AM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9

     Anyone have any clue??

  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-05-2009, 3:45 AM
    Answer

    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-05-2009, 8:50 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    Oh man that worked smoothly!!
    Thank you very much for helping

    Have a nice day :)

    Regards, Felipe
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-05-2009, 10:29 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    I'll use this same thread to raise another problem happening right after solving the old one:

    The postback is working fine now, however the Click event of the LinkButton is not being fired.
    Is there any other special handling I need to do to make the event work correctly? The LinkButton is being added dynamically to the page. Here is the code snippet:

    LinkButton linkFileBtn = new LinkButton();
    linkFileBtn.Text = file.Name;
    linkFileBtn.Click += new EventHandler(SelectedFileChanged);
    linkFileBtn.Attributes.Add("runat", "server");
    linkFileBtn.CssClass = "fileentry";
    linkFileBtn.ID = "file_" + Guid.NewGuid();
    m_lstFiles.Add(linkFileBtn);
    m_scriptManager.RegisterAsyncPostBackControl(linkFileBtn);


    The problem is that SelectedFileChanged method is not being fired.

    Any other clue guys?

    Thanks,
    Felipe
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-05-2009, 11:13 PM

    Hi,

    There are two potential causes.

    1. Some methods in SelectedFileChanged event is not supported in UpdatePanel.

    For example, "ClientScript.RegisterXXX" is not supported in UpdatePanel, we have to use ScriptManager.RegisterXXX instead.

    In additional, Response.Write, FileUpload control and so on are not supported either.

    2. The class isn't inherited by INameContainer interface.

     

    If you still stumbled on it, please post your SelectedFileChanged event.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-06-2009, 6:15 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    This is the code for SelectedFileChanged
    protected void SelectedFileChanged(object sender, EventArgs e)
    {
    this.m_sSelectedFilePath = GetSelectedFolder() + "/" + ((LinkButton)sender).Text;
    }
    private string GetSelectedFolder()
    {
    TreeNode t = m_treeFolders.SelectedNode;
    string sFullPath = t.ValuePath;
    return sFullPath.Remove(0, sFullPath.IndexOf('/') + 1);
    }

    I don't see any of the causes you mentioned here. BTW, I'm using Page.ClientScript.RegisterClientScriptResource to register a javascript file in the OnPreRender method. This is my only concern.

    Thanks,
    Felipe
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-06-2009, 9:06 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9
    No clues yet :(
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-08-2009, 9:40 PM
    Answer

    Hi,

    Can you make use of breakpoint or add an additional code to check whether SelectedFileChanged event is not triggered at all or the event was invoked but the code in SelectedFileChanged was not worked?

    In addition, if you want to upload file in UpdatePanel, it will not be work. UpdatePanel doesn't support FileUpload.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-10-2009, 6:17 AM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9

    Hi

    I did that and noticed that the code is not even triggered at all... Does anyone know reason for the code behind event not being fired at all?

    I can't find a solution anywhere. This is driving me crazy

  • Re: Postback problem in ModalPopupExtender with LinkButton

    02-10-2009, 12:34 PM
    • Member
      2 point Member
    • felipecsl
    • Member since 02-03-2009, 9:38 PM
    • Posts 9

     I found this post (http://bytes.com/groups/net/48218-linkbutton-click-event-handler-not-executing) where someone say that the dynamic control needs to be recreated on the postback for the event handler to be called.

    Is that true? How can this be achieved?

    Thanks

Page 1 of 1 (12 items)