Problem with UpdatePanel and RenderMode="Inline"

Last post 05-09-2008 8:37 AM by Anders Malmgren. 9 replies.

Sort Posts:

  • Problem with UpdatePanel and RenderMode="Inline"

    05-07-2008, 3:58 AM

    Hi all!
    I have some updatepanels on a e-comerce site im working on.
    They have worked perfect up till now.

    When you click at a LinkButton I register this script at postback,

    ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "initBG", "init();", true);

    What it does is basicly to do some flashy javacript thingy on the htmlelements in one of the updatepanels.
    This have worked great and the init() method only executes when i click the LinkButton.

    The problem:
    The UpdatePanel default render mode is Block, this has impacts on layout so i have changed to render mode inline instead.

    But after i did this the init() script is fired each time i do any postback not only the LinkButton postback i talked about earlier.

    How can i get it it to work as before but with rendermode="inline"?
     

    Best regards,
    Anders Malmgren

  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-07-2008, 11:43 AM

    Anders,

    I'm pretty sure the render mode only affects whether the UpdatePanel is rendered as a div tag or a span tag, so it is dubious that this is the cause of the change in behavior.  Are you sure you didn't change anything else when you changed the rendermode?

    Can you show some of the relevant code, both aspx and code behind, so we can see how your objects are nested?

    James

     

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-07-2008, 11:18 PM

    If the RenderMode property is set to Inline, the content of an UpdatePanel control is rendered inside an HTML <span> element. If the RenderMode property is set to Block, it is rendered inside an HTML <div> element.

    http://asp.net/AJAX/Documentation/Live/mref/P_System_Web_UI_UpdatePanel_RenderMode.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 2:55 AM

    Thanks for a prompt reply, 100% positive its the rendermode that causes this because if i change back to block it works again.

    I've also tried to keep it has a div but set its style property to style="display: inline" and this gives me the same behavior with the script as when asp.net renders it has a span. It happens both in IE and FF

    edit:you can take a look at the testsite here, http://213.89.145.234/sjc/?id=2
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 9:21 AM

    Anders,

    The site looks good.  It's hard to understand what's going on without some code to look at, though.

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 9:39 AM

     Thanks, ofcource the layout is not done yet, i have just put everything on the form to get a feel of things to come...

     

    Anyway.. The updatepanel that shows the product detail screen  (the overlay scren that appears when you click a thumbnail)

     

    has this aspxcode

     

            <asp:UpdatePanel ID="articleDetailsUP" UpdateMode="Conditional" RenderMode="Inline" runat="server">
    <ContentTemplate>
    <asp:PlaceHolder ID="articlePanel" Visible="false" runat="server">
    <div id="productContainer">
    <asp:Image ID="image" CssClass="image" runat="server" />
    <div class="thumbs">
    <asp:Repeater ID="imagesRepeater" runat="server">
    <ItemTemplate>
    <asp:Image ID="thumb" runat="server" />
    </ItemTemplate>
    </asp:Repeater>
    </div>
    <div>
    <span>Art.Nr</span> <asp:Literal ID="articleNr" runat="server" /><br />
    <asp:Label ID="lblPrice" runat="server" /> <asp:Literal ID="price" runat="server" /><br />
    <asp:Literal ID="description" runat="server" />
    <div><asp:LinkButton ID="btnClose" OnClientClick="destroy();" CssClass="btnClose" OnClick="CloseClick" runat="server"><img src="img/layout/close.gif" alt="Stäng" /></asp:LinkButton></div>
    </div>
    </div>
    <div id="layerBG"></div>
    </asp:PlaceHolder>
    </ContentTemplate>
    </asp:UpdatePanel>

     

    And when you click a product this code is fired

        public void ShowArticle(int articleId)
    {
    article = Controller.GetArticleWithFullInfo(articleId);
    image.ImageUrl = string.Format("~/img/image.aspx?id={0}", article.ImageId);
    image.AlternateText = article.ArticleNr;
    articleNr.Text = article.ArticleNr;
    lblPrice.FormatAsPriceLabel(article);
    price.Text = Math.Round(article.OutPrice, 0).ToString();
    description.Text = article.Description;

    if (article.Images.Count > 1)
    {
    imagesRepeater.ItemDataBound += new RepeaterItemEventHandler(ImagesRepeaterItemDataBound);
    imagesRepeater.DataSource = article.Images;
    imagesRepeater.DataBind();
    imagesRepeater.Visible = true;
    }
    else imagesRepeater.Visible = false;

    ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "initBG", "init();", true);
    articlePanel.Visible = true;
    articleDetailsUP.Update();
    }

      when you click the close button this code is fired

      

        protected void CloseClick(object sender, EventArgs e)
        {
            articlePanel.Visible = false;
            articleDetailsUP.Update();
        }  
     
     If the rendermode is set to inline the init() method will be fired everytime a ayncpostback is made, if its set to block it will only fire when you click on a product and ShowArticle(int articleId) is fired...

     

  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 10:55 AM

    Anders,

    Thanks.  This clears things up a bit.  As I understand it, the script you are registering will fire off a client side function to do certain things when the page refreshes -- if the correct linkbutton is fired.  I'm curious as to why you use the RegisterClientScriptBlock method instead of RegisterStartupScript, though.  The first one is unreliable if your goal is to always have this run on postback -- RegisterStartupScript seems, to me, to be the method you really want.

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 11:36 AM

    Well RegisterStartupScript will fire the script eachtime ANY postback is made. I only want it to fire the script when a certain postback is made. And this is how the RegisterClientScriptBlock did work before i changed it to rendermode="inline" now the script is fired everytime any kind of postback is made.

     I only want the script to fire whe the ShowArticle() method has been fired server side...
     

  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-08-2008, 11:50 AM

    Anders,

    I did a quick prototype, based on your posted code, replacing RegisterClientScriptBlock with RegisterStartupScript, and it seemed to work the way you want.  I had two LinkButtons, one of which injected the script and one that did nothing, both in the update panel. 

    Can you make the switch and see what happens?

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Problem with UpdatePanel and RenderMode="Inline"

    05-09-2008, 8:37 AM
    Answer

     i havent changed anything and now all of the sudden it works both with RegisterStartupScript and RegisterScriptBlock.. very strange?!?!? Stick out tongue

     Well, im glad it worked :D

Page 1 of 1 (10 items)