Set Focus on PostBack

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #16
    As much as I hate to admit it (:-P) if you run it in firefox with that DOM parser thing on you will see a lot more hidden errors.

    Are you remembering to have your body tag's onload function call out to that javascript onload thing

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #17
      I'm going to ask one more small but vital question.

      Are you using any use of Ajax in your html design?
      Are you using the AjaxControlTool kit's UpdatePanel?

      Comment

      • erickme
        New Member
        • Jul 2007
        • 8

        #18
        I just tried with firefox and it works, but not with Internet explorer. I didn't get any javascript error. I don't get it, whats wrong with IE (lol) then.

        I'm not using AJAX in this application, this is an old application, it was develop long time before I started working here.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #19
          Originally posted by erickme
          I just tried with firefox and it works, but not with Internet explorer. I didn't get any javascript error. I don't get it, whats wrong with IE (lol) then.

          I'm not using AJAX in this application, this is an old application, it was develop long time before I started working here.
          Have you checked out w3c?
          Have you seen their focus() method example?

          I tried their example in IE and it works fine....
          Maybe you might find then answer in w3c.

          Comment

          • erickme
            New Member
            • Jul 2007
            • 8

            #20
            Originally posted by Frinavale
            Have you checked out w3c?
            Have you seen their focus() method example?

            I tried their example in IE and it works fine....
            Maybe you might find then answer in w3c.
            It doesn't seem to work with a asp button, I got this error:
            Compiler Error Message: BC30390: 'ASPNET.Starter Kit.Portal.Prod uctLookUpPage.P rivate Sub SetFocus(Client ID As String)' is not accessible in this context because it is 'Private'.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #21
              Originally posted by erickme
              It doesn't seem to work with a asp button, I got this error:
              Compiler Error Message: BC30390: 'ASPNET.Starter Kit.Portal.Prod uctLookUpPage.P rivate Sub SetFocus(Client ID As String)' is not accessible in this context because it is 'Private'.
              Could you post the html code for your aspx page?

              Comment

              • nateraaaa
                Recognized Expert Contributor
                • May 2007
                • 664

                #22
                Originally posted by erickme
                It doesn't seem to work with a asp button, I got this error:
                Compiler Error Message: BC30390: 'ASPNET.Starter Kit.Portal.Prod uctLookUpPage.P rivate Sub SetFocus(Client ID As String)' is not accessible in this context because it is 'Private'.
                '07/20/07 This procedure sets focus to specific controls.
                Private Sub SetFocus(ByVal ClientID As String)
                Dim Script As New System.Text.Str ingBuilder
                'Dim ClientID As String = FocusControl.Cl ientID
                With Script
                .Append("<scrip t language='javas cript'>")
                .Append("docume nt.getElementBy Id('")
                .Append(ClientI D)
                .Append("').foc us();")
                .Append("</script>")
                End With
                RegisterStartup Script("setFocu s", Script.ToString ())
                End Sub

                Change the SetFocus method to be a public method instead of a private method.

                Nathan

                Comment

                • erickme
                  New Member
                  • Jul 2007
                  • 8

                  #23
                  Here is the html

                  [CODE=html]
                  <body bottomMargin="0 " leftMargin="0" topMargin="0" rightMargin="0" marginwidth="0" marginheight="0 ">
                  <form runat="server">
                  <table cellSpacing="0" cellPadding="0" width="100%" border="0">
                  <tr vAlign="top">
                  <td colSpan="2"><as p:placeholder id="phBanner" runat="server"> </asp:placeholder ></td>
                  </tr>
                  <tr>
                  <td class="contentC ellTop" vAlign="top">
                  <center><br>
                  <table width="650" border="0">
                  <tr>
                  <td>
                  <TABLE id="Table1" cellSpacing="2" cellPadding="2" width="100%" border="0">
                  <TR>
                  <TD>
                  <asp:label id="lblTitle" runat="server" CssClass="Head" > Product Locate</asp:label></TD>
                  <TD>
                  <P align="right">[
                  <asp:linkbutt on id="lnkReturn0 " CssClass="Comma ndButton" Visible="True" Runat="server" EnableViewState ="True"
                  Enabled="True" CausesValidatio n="False">retur n</asp:linkbutton>]</P>
                  </TD>
                  </TR>
                  </TABLE>
                  <HR noShade SIZE="1">
                  <span class="normal" id="spnContent " runat="server">
                  <P>Enter a Product Code (PCode) or look it up using the look-up function provided.&nbsp; Once you select a product,
                  you can find a display of stores which have the product in stock as of&nbsp;end
                  of business&nbsp;y esterday.</P>
                  <P><asp:validat ionsummary id="vsPCode" runat="server" CssClass="Error " Width="100%" HeaderText="The following error(s) occurred:"></asp:validations ummary></P>
                  <P align="center"> <asp:textbox id="txtPCode" runat="server" Width="63px" ToolTip="Enter the PCode into this textbox."></asp:textbox><as p:requiredfield validator id="rfvPCode" runat="server" CssClass="strEr ror" ToolTip="You must enter a valid PCode to continue."
                  ControlToValida te="txtPCode" Display="Dynami c" ErrorMessage="Y ou must enter a valid PCode to continue.">!</asp:requiredfie ldvalidator><as p:regularexpres sionvalidator id="revPCode" runat="server" CssClass="strEr ror" ToolTip="The PCode can only contain 5 or 6 numbers."
                  ControlToValida te="txtPCode" Display="Dynami c" ErrorMessage="T he PCode can only contain 5 or 6 numbers." ValidationExpre ssion="\d{5,6}" >!</asp:regularexpr essionvalidator ><asp:customval idator id="cvPCode" runat="server" CssClass="strEr ror" ToolTip="The Product Code entered was not found."
                  Display="Dynami c" ErrorMessage="T he Product Code entered was not found." EnableClientScr ipt="False" OnServerValidat e="ValidatePCod e">!</asp:customvalid ator>&nbsp;
                  <asp:button id="cmdLocate" runat="server" CssClass="Comma ndButton" ToolTip="Click here to locate the product."
                  Text="Locate"></asp:button>&nbs p; <INPUT class="CommandB utton" id="cmdLookup" onclick="this.d isabled = true; NewWindow('prod uct_lookup.aspx ','ProductLookU p',550,500,0,'c enter');"
                  type="button" value="Look-Up PCode" name="cmdLookup "></P>
                  <P align="center">
                  <TABLE id="tblInfoCont ainment" cellSpacing="2" cellPadding="2" width="475" border="0">
                  <TR>
                  <TD vAlign="top">
                  <TABLE id="tblResultsL abels" cellSpacing="3" cellPadding="3" border="0">
                  <TR>
                  <TD class="strNorma l" colSpan="4">Cli ck the LOCATE button to initiate the query.</TD>
                  </TR>
                  <TR class="Normal">
                  <TD>
                  <asp:label id="lblPCodeVal ue" runat="server" CssClass="strNo rmal"></asp:label></TD>
                  <TD colSpan="2">
                  <P align="left">
                  <asp:label id="lblDescValu e" runat="server" CssClass="Norma l"></asp:label></P>
                  </TD>
                  <TD>
                  <asp:label id="lblSizeValu e" runat="server" CssClass="Norma l"></asp:label></TD>
                  </TR>
                  <TR>
                  <TD colSpan="2">
                  <asp:Label id="lblWHHead" runat="server" CssClass="strNo rmal" Visible="False" >Warehouse O/H:</asp:Label>&nbsp ;
                  <asp:Label id="lblWHQty" runat="server" CssClass="Norma l"></asp:Label></TD>
                  <TD colSpan="2">
                  <asp:Label id="lblStoreHea d" runat="server" CssClass="strNo rmal" Visible="False" >Your Store O/H:</asp:Label>&nbsp ;
                  <asp:Label id="lblStoreQty " runat="server" CssClass="norma l" Visible="False" ></asp:Label>&nbsp ;</TD>
                  </TR>
                  </TABLE>
                  </TD>
                  <TD vAlign="bottom" ><INPUT id="btnPriceIt " type="button" value="Price It!" name="btnPriceI t" runat="server"
                  class="CommandB utton" tooltip="Click here to see the prices of the product in the different price zones">&nbsp;</TD>
                  </TR>
                  </TABLE>
                  </P>
                  <P align="center">
                  </P>
                  <P align="center"> <asp:datalist id="dlProductNu mbers" runat="server" CssClass="Norma l" Width="100%" RepeatColumns=" 5"
                  CellPadding="3" BorderColor="#D EBA84" BorderStyle="No ne" BackColor="#DEB A84"
                  GridLines="Both " BorderWidth="1p x" CellSpacing="2" >
                  <SelectedItemSt yle Font-Bold="True" ForeColor="Whit e" BackColor="#738 A9C"></SelectedItemSty le>
                  <HeaderTemplate >
                  <TABLE id="tblDataHead er" cellSpacing="0" cellPadding="3" width="100%" border="0">
                  <TR>
                  <TD align="center" class="strNorma l" style="color: #ffffff;">The Product has been
                  found in the following Stores:</TD>
                  </TR>
                  </TABLE>
                  </HeaderTemplate>
                  <FooterStyle ForeColor="#8C4 510" BackColor="#F7D FB5"></FooterStyle>
                  <ItemStyle ForeColor="#8C4 510" BackColor="#FFF 7E7"></ItemStyle>
                  <ItemTemplate >
                  <table id="tblDataItem " border="0" cellpadding="3" cellspacing="0" width="100%">
                  <TR>
                  <td align="left" class="strNorma l"><a href='<%# "../store_info_look up.aspx?storenu mber=" & DataBinder.Eval (Container.Data Item, "STORE_NO")%>'> Store
                  <%# DataBinder.Eval (Container.Data Item, "STORE_NO") %>
                  </a>
                  <span class="Normal"> (<%# DataBinder.Eval (Container.Data Item, "END_QTY")% >)</span>
                  </TR>
                  </table>
                  </ItemTemplate>
                  <HeaderStyle Font-Bold="True" ForeColor="#DEB A84" BackColor="#A55 129"></HeaderStyle>
                  <AlternatingIte mTemplate>
                  <table id="tblDataAltI tem" border="0" cellpadding="3" cellspacing="0" >
                  <TR>
                  <td align="left" class="strNorma l"><a href='<%# "../store_info_look up.aspx?storenu mber=" & DataBinder.Eval (Container.Data Item, "STORE_NO")%>'> Store
                  <%# DataBinder.Eval (Container.Data Item, "STORE_NO") %>
                  </a>
                  <span class="Normal"> (<%# DataBinder.Eval (Container.Data Item, "END_QTY")% >)</span>
                  </TR>
                  </table>
                  </AlternatingItem Template>
                  </asp:datalist></P>
                  <P align="left"><S TRONG><U>Tip</U>:</STRONG> Hold down the shift&nbsp;key when you click on a store number to open
                  the store information in a new window.</P>
                  <P>[<asp:linkbutt on id="lnkReturn1 " runat="server" cssclass="Comma ndButton" borderstyle="no ne" text="Return"
                  causesvalidatio n="False">retur n</asp:linkbutton>]</span></P>
                  <P>&nbsp;</P>
                  </td>
                  </tr>
                  </table>
                  </center>
                  </td>
                  </tr>
                  <tr>
                  <td class="contentC ellBottom">&nbs p;</td>
                  </tr>
                  <tr>
                  <td class="FootBg" vAlign="middle" height="30">
                  <div align="center"> <span class="SiteLink "><font color="#eeeeee" >Thank you for visiting
                  ABCNet.</font></span></div>
                  </td>
                  </tr>
                  </table>
                  </form>
                  </body>
                  [/CODE]

                  Comment

                  • erickme
                    New Member
                    • Jul 2007
                    • 8

                    #24
                    Originally posted by nateraaaa
                    '07/20/07 This procedure sets focus to specific controls.
                    Private Sub SetFocus(ByVal ClientID As String)
                    Dim Script As New System.Text.Str ingBuilder
                    'Dim ClientID As String = FocusControl.Cl ientID
                    With Script
                    .Append("<scrip t language='javas cript'>")
                    .Append("docume nt.getElementBy Id('")
                    .Append(ClientI D)
                    .Append("').foc us();")
                    .Append("</script>")
                    End With
                    RegisterStartup Script("setFocu s", Script.ToString ())
                    End Sub

                    Change the SetFocus method to be a public method instead of a private method.

                    Nathan
                    I set it to public but still gives me an error

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #25
                      Originally posted by erickme
                      It doesn't seem to work with a asp button, I got this error:
                      Compiler Error Message: BC30390: 'ASPNET.Starter Kit.Portal.Prod uctLookUpPage.P rivate Sub SetFocus(Client ID As String)' is not accessible in this context because it is 'Private'.
                      You are getting this error because your button has a runat=server.
                      So since it is an asp button, it is trying to call the server side code called SetFocus (except this function is private and so you get an error). It is not calling the JavaScript function called SetFocus as because it is an asp button and is calling the Server Side code.

                      In order to call JavaScript using an asp button you'd have to do something like the following in your in your server side code:

                      BTN_MyButton.At tributes.Add("O nMouseUP", "SetFocus(' " + TXT_myTextBox.C lientID"');")

                      However, the asp button will cause a PostBack event.
                      Since this happens your focus will be lost when the page is redisplayed in the browser.

                      If you were following the example from the w3c site and substituted the <input type="button"> for <asp:Button>, the example will obviously not work for these reasons.

                      -Frinny

                      Comment

                      Working...