简体   繁体   中英

TextBox doesnt transfer value on singleclick asp.net c#

If I write something in a textbox and hit the button, the value of the textbox is still empty. It works if I click somewhere else first (in any white space, just out of the textbor) or if I click the button twice.

Is there any workaround? My Code:

  <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <ContentTemplate>
                <asp:Label ID="lblStatus" runat="server" Text="lblStatus"></asp:Label>
                <br />Selektion Typ:
                <br />
                <asp:DropDownList ID="DropDownListLamellentyp" runat="server" onselectedindexchanged="DropDownListLamellentyp_SelectedIndexChanged" 
                                 Visible="True"  Font-Size="Large" AutoPostBack="true" CSSClass="dropDownList">
                </asp:DropDownList>
                <br />
                <br />Selektion Variante:
                <br />
                <asp:DropDownList ID="DropDownListVariant" runat="server" 
                    AutoPostBack="True"
                    onselectedindexchanged="DropDownListVariant_SelectedIndexChanged"  
                    Visible="True" CSSClass="dropDownList" Font-Size="Medium">
                </asp:DropDownList>
                <br />
                <br />
                Fertighöhe eingeben:<br />
                <asp:TextBox ID="txtFertighoehe" runat="server" AutoPostBack="True" 
                    BackColor="#CCFFCC" Font-Bold="True" Font-Size="XX-Large" Height="48px" 
                     Width="190px"></asp:TextBox>
                <asp:Image ID="Image1" runat="server" Height="34px" 
                    ImageUrl="~/pakethoehen1.jpg" Width="69px" />
                <br />
                <br />
                <asp:Button ID="btnCalculate" runat="server" onclick="btnCalculate_Click" 
                 Text="Berechnen" Enabled="False" CSSClass="button" />
                <br />
                <br />
                <asp:Label ID="LabelMessage" runat="server" Text="..." Font-Bold="True" Font-Size="Large"></asp:Label>
            </ContentTemplate>
            </asp:UpdatePanel>

This is because you are given AutoPostBack="True" for the textbox control, so if you comes out from the textbox the page get refreshed, hence the data is resetted. so remove it if you don't want text change event.make it false .

<asp:TextBox ID="txtFertighoehe" runat="server" AutoPostBack="false" 
                    BackColor="#CCFFCC" Font-Bold="True" Font-Size="XX-Large" Height="48px" Width="190px"></asp:TextBox> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM