server controls inside asp:wizard, doesnt render jscript if step is not first..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Louis Dupont

    #1

    server controls inside asp:wizard, doesnt render jscript if step is not first..

    I'm trying to use a server control inside a template wizard step, when I drop such server control in the first step of the wizard everything goes ok.
    When I insert even a blank step previous to the step which contains the server control, the javasript code of the server control is not rendered at all, the page doesn't fail during load but until I go with mouse over an item of the grid for instance.
    When I check the rendered HTML I can see no HTML, nor javascript events of this server control where rendered, neither the implementation nor calls to javascript, but even rarer what is there visible in the grid for ie, even the other components of the server control, are not in the "view source code" content.
    I seems it was sent to the client, even showed, but truncated in some phase..

    Thanks in advance for your comments,
    Louis.
    PD:
    The server control consists of a gridview with custom navigation&info rmation capabilities and javascript functions to highlight the selected grid items or highlight when mouse over event occurs.. (full tested outside asp:wizard)
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It would really help if you posted the code that is responsible for generating and registering the JavaScript so that we can help you solve this problem.

    Also, are you using an UpdatePanel along with the wizard?

    -Frinny

    Comment

    • Louis Dupont

      #3
      Thanks a lot for your reply. Yes I'm using an UpdatePanel which contains the wizard.
      PAGE CODE:
      ..
      Code:
      <asp:UpdatePanel ID="updatePanelWizard" runat="server" >
      <ContentTemplate> 
        <asp:Wizard ID="wzdE" runat="server" ..
          <SideBarTemplate> .. </SideBarTemplate>
          <StepStyle .. />
          <StepNavigationTemplate> .. </StepNavigationTemplate>
          <WizardSteps>
            <asp:TemplatedWizardStep ID="Step1" runat="server"..
              <ContentTemplate>
                <uc1:MyServerControl .. runat="server"/>
              </ContentTemplate>
              <CustomNavigationTemplate> ..
              </CustomNavigationTemplate>
            </asp:TemplatedWizardStep>
            <asp:TemplatedWizardStep ID="Step2" runat="server"..
              <ContentTemplate>
                <!-- Server control (uc1) doesn't work here -->
              </ContentTemplate>
              <CustomNavigationTemplate> ..
              </CustomNavigationTemplate>
            </asp:TemplatedWizardStep>
          </WizardSteps>
          ..
        </asp:Wizard>
      </ContentTemplate>
      </asp:UpdatePanel>
      ..
      SERVER CONTROL:Works great in anyother place even in step 1
      Code:
      public class cSCDataGrid : WebControl, INamingContainer 
      {
        protected DataGrid fGrid = new DataGrid();
        ...
        protected string generateJavaScriptCode()
        {		
          String scriptCode = ((flAllowHighlightOnMouseOver)?
            "function HighlightRowOnMouseOver(row) { " +
              "if (row.style.backgroundColor!='#336666') " +
                "{ if (row.tabIndex==1) { " +
                    "row.style.backgroundColor='#F0FFC0'; } " +
                   "else { "+
                    "row.style.backgroundColor='#F0FFC0'; }}} ":
             "");
          return scriptCode;
        }
        protected override void CreateChildControls() 
        {
          ..
          this.Controls.Add(new LiteralControl(
            "<script language='javascript' " +   
                "type='text/jscript'> " + ..
              (flAllowHighlightOnMouseOver?
                 generateJavaScriptCode():"") +
            "</script> ")); 
          fGrid.ItemDataBound += 
            new DataGridItemEventHandler(grid_ItemDataBound); 
        }
        private void grid_ItemDataBound(object sender,
          DataGridItemEventArgs e)
        {
          if ((e.Item.ItemType==ListItemType.Item) ||
              (e.Item.ItemType==ListItemType.AlternatingItem))
            ..
            if (flAllowHighlightOnMouseOver)
              e.Item.Attributes.Add("OnMouseOver",
                "javascript:HighlightRowOnMouseOver(this);");
        }
        ..
      }
      Last edited by Frinavale; Sep 30 '10, 03:54 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Ahha...There's your problem: you are out putting JavaScript into a Literal control and you are expecting it to work within an UpdatePanel.

        When you are using UpdatePanels, any control within the UpdatePanel will cause asynchronous postbacks to the server.

        In this case, if you do not register JavaScript methods that your controls use with the ScriptManager, then your JavaScript will stop working after any asynchronous requests occur. This is why your control works in the first step, but not in subsequent steps.

        The ScriptManager control has a bunch of methods that allow you to register JavaScript with it. Go through them and find something that is appropriate for your situation (for example the ScriptManager.R egisterClientSc riptBlock Method (Control, Type, String, String, Boolean) Method might be a good choice for you).

        -Frinny

        Comment

        • Louis Dupont

          #5
          Thanks a lot Frinny, it was the right answer.. I have documented a bit more here: http://forums.asp.net/p/1608116/4109986.aspx.

          Comment

          Working...