How can I achieve this?

Last post 05-09-2008 8:54 AM by ramblor. 1 replies.

Sort Posts:

  • How can I achieve this?

    05-09-2008, 8:12 AM
    • Loading...
    • cmarks
    • Joined on 05-07-2008, 2:25 PM
    • UK
    • Posts 13

    Hi,

    I've got a webform, which takes customer details in, - if the customers time at their address is less than 3 years, I need to take a previous address, but I don't want the previous adress entry fields visible, if this is not the case, and when the page is first loaded.

     Currently, I'm testing - the previous address fields will eventually be contained in a panel I guess - but for the time being I'm practising with a label.

    I've got my form fields txtYears and txtMonths in a normal HTML table - the months text field has AutoPostBack enabled - and these two fields are contained within an UpdatePanel so I dont refresh the whole page (I'd like this to be fluid).  My code behind is simply:

     

            if (Page.IsPostBack)
            {
                int Years = Convert.ToInt32(txtYears.Text);
                int Months = Convert.ToInt32(txtMonths.Text);
                int TotalMonths = ((Years * 12) + Months);
                if (TotalMonths < 36)
                {
                    Label1.Visible = true;
                }
                else
                {
                    Label1.Visible = false;
                }
            }

     - eventually I guess I'd like the Label1 to be the Panel, but as the Label is outside of the update panel, it's not being shown (it's invisible at startup) - is there anyway that I can achieve this?

     

    Thanks

  • Re: How can I achieve this?

    05-09-2008, 8:54 AM
    • Loading...
    • ramblor
    • Joined on 03-13-2008, 10:03 AM
    • Posts 555

    I'd probably try and do it just using javascript and css rather than an UpdatePanel. Here's an example in case it helps:

    -- aspx page --
    <asp:TextBox ID="TextBoxYears" runat="server" onblur="CheckTime();" />
    <asp:TextBox ID="TextBoxMonths" runat="server" onblur="CheckTime();" />
    <asp:Panel ID="PanelAddress" runat="server" CssClass="hide">
        This is the other address panel
    </asp:Panel>

    -- javascript --
    function CheckTime()
    {
        var y = document.getElementById("<%=TextBoxYears.ClientID%>").value;
        var m = document.getElementById("<%=TextBoxMonths.ClientID%>").value;
       
        y = parseInt(y,10);
        m = parseInt(m,10);
        if(isNaN(y)) y = 0;
        if(isNaN(m)) m = 0;
       
        var tot = (y*12) + m;
        var pnl = document.getElementById("<%=PanelAddress.ClientID%>");

        pnl.className = (tot < 36) ? "show" : "hide";
    }

    -- css --
    .hide
    {
        display: none;
    }
    .show
    {
        display: block;
    }

     

    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
Page 1 of 1 (2 items)