在asp.net中自动调用文本框TextChanged事件 [英] call text box textchanged event automatically in asp.net

查看:396
本文介绍了在asp.net中自动调用文本框TextChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我在哪里导航到我的一个形式的形式,其中我有量的文本框。 previously我进入量。现在,IO有一个工作流程是这样的其他形式来在画面的原因。现在,我大量的编码做我的文本框中的文本改变事件。当我做的Response.Redirect 形式其他形式的,我也流数量,并将该数量在该文本框。现在,我不想写一个新的code(功能)做相同的程序选择更新也将完成。以下是我的code这我试图执行并调用文字更改事件。我也使用更新面板。那么,请问这是为什么我的事件不会被解雇的原因是什么?上的任何解决方案,。??

I have a form from where I am navigating to a form of mine where I have a text box for quantity. Previously I was entering the quantity. Now, IO have a work flow that is the reason the other form comes in picture. Now, I have extensive coding done my text box text changed event. When I do response.redirect form other form, I flow quantity also and put that quantity in that text box. Now i dont want to write a new code(function) for doing the same as updation procedure will also be done. Following is my code which I am trying to execute and call the text changed event. I am also using update panel. So, is that the reason why my event is not getting fired.? Any solution on that,.??

txt_Quantity.TextChanged += new EventHandler(txt_Quantity_TextChanged);



protected void txt_Quantity_TextChanged(object sender, EventArgs e)
    {
    }





 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

            <asp:Panel ID="pnlGrid" runat="server" BorderColor="#339933" Height="400px" BorderStyle="Solid"
                BorderWidth="2px" ScrollBars="Auto" Width="100%">



                <div style="height: 40px; width: 100%; background-color: #339933;">
                    <%-- <img alt="imgrid" src="Images/grid_icon_green.png" style="padding-left: 10px;" />--%>
                    <span style="font-size: 20px; font-family: Calibri; color: White; padding-left: 5px; vertical-align: top">Asset Distribution</span>
                </div>

                <AjaxToolKit:TabContainer ID="TabContainer1" runat="server" Height="400px">
                    <AjaxToolKit:TabPanel ID="tab1" runat="server" TabIndex="0" HeaderText="Basic Information">
                        <ContentTemplate>
                            <table width="100%">

                                <tr>

                                    <td class="r1">Last Code:

                                    </td>
                                    <td>
                                        <asp:Label ID="Lbl_AssetDistriCode" runat="server"></asp:Label>
                                    </td>




                                    <td width="10%" class="r1">Item Code:
                                    </td>
                                    <td width="23%">

                                        <asp:TextBox ID="txt_ItemCode" runat="server" Height="95%" Width="150px" CssClass="txtbxcomp" AutoPostBack="true" OnTextChanged="txt_ItemCode_TextChanged"></asp:TextBox>
                                       <%-- <span style="color: Red;">*</span>--%>
                                        <AjaxToolKit:AutoCompleteExtender ID="AutoCompleteExtender4" runat="server" ServiceMethod="getitem"
                                            ServicePath="WebService.asmx" TargetControlID="txt_ItemCode" CompletionInterval="500"
                                            MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="5">
                                        </AjaxToolKit:AutoCompleteExtender>

                                    </td>

                                    <td width="10%"></td>
                                    <td width="24%"></td>
                                </tr>


                                <tr>

                                    <td class="r1" width="10%">Item Group:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Item_Grp" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Item_Grp_SelectedIndexChanged">
                                        </asp:DropDownList>
                                       <%-- <span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Item Type:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Item_typ" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Item_typ_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="14%">Item Catagory:
                                    </td>
                                    <td width="20%">
                                        <asp:DropDownList ID="ddl_Item_cat" runat="server" Height="95%" Width="150px" CssClass="drpComp"></asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                </tr>


                                <tr>

                                    <td class="r1" width="10%">City:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_city" runat="server" Height="95%"  Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_city_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Location:
                                    </td>
                                    <td width="24%">
                                        <asp:DropDownList ID="ddl_Loc" runat="server" Height="95%" Width="150px" CssClass="drp" 
                                          >
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Branch:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Branch" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Branch_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>


                                </tr>




                                 <tr>

                                      <td class="r1" width="10%">Department:
                                    </td>
                                    <td width="24%">
                                        <asp:DropDownList ID="ddl_Dept" runat="server" Height="95%" Width="150px" CssClass="txtbx" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Dept_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>


                                    <td class="r1" width="10%">User:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_User" runat="server" Height="95%" width="150px" CssClass="txtbx"  AutoPostBack="True"></asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <%--<td class="r1" width="15%">Asset Code:
                                    </td>
                                    <td width="19%">
                                        <asp:DropDownList ID="ddl_Asset_code" runat="server" Height="95%" CssClass="txtbx" AutoPostBack="True"></asp:DropDownList>
                                        <span style="color: Red;">*</span>
                                    </td>--%>
                                    <td class="r1" width="10%">Quantity:
                                    </td>
                                    <td width="23%">
                                        <asp:TextBox ID="txt_Quantity" runat="server" Height="95%" Width="150px"  CssClass="txtbxcomp" AutoPostBack="true" OnTextChanged="txt_Quantity_TextChanged"></asp:TextBox>
                                        <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" TargetControlID="txt_Quantity"
                                            ValidChars="0123456789." Enabled="True">
                                        </cc1:FilteredTextBoxExtender>


                                       <%-- <span style="color: Red;">*</span>--%>

                                    </td>
                                    <td width="10%"></td>
                                    <td width="24%"></td>

                                </tr>



                                <%--<tr>
                                    <td width="15%" class="r1">Mac ID:
                                    </td>
                                    <td width="18%">

                                        <asp:TextBox ID="txt_MacId" runat="server" Height="95%" CssClass="txtbx"></asp:TextBox>
                                        <span style="color: Red;">*</span>
                                    </td>
                                    <td width="15%"></td>
                                    <td width="18%"></td>
                                    <td width="15%"></td>
                                    <td width="19%"></td>
                                </tr>--%>
                            </table>
                        </ContentTemplate>
                    </AjaxToolKit:TabPanel>

</ContentTemplate>

        <Triggers>

            <asp:PostBackTrigger ControlID="btnSave" />
            <asp:PostBackTrigger ControlID="btnUpdate" />
            <asp:PostBackTrigger ControlID="btndelete" />
            <asp:PostBackTrigger ControlID="btnClear" />

        </Triggers>

    </asp:UpdatePanel>

先谢谢了。

推荐答案

OnTextChanged 如果您在文本框的变化,也是卡出了场才会发生。或者可以说在文本框中输入的AutoPostBack 将触发回发时,焦点从文本框丢失。

The OnTextChanged will only occur if you make a change in the textbox and also tab out of the field. OR you can say AutoPostBack on text box will trigger postback when the focus is lost from the text box.

,而你是在文本框中键入 OnTextChanged 事件不被解雇。 OnTextChanged 是一个服务器端事件,只有触发时页面被调回。键入到一个页面上的文本框不发布页面回来,所以这个事件只火一次页面被喜欢不同的方式发布:点击链接等。所以,你要确保文本被改变后,你搬出去文本框。

the OnTextChanged event is NOT fired while you are typing in the text box. OnTextChanged is a server-side event and only fires when the page is posted back. Typing into a text box on a page does not post the page back and so this event will only fire once page is posted by different way like: button click etc.. So you make sure that after the text is changed, you are moving out of text box.

使用更新面板是好的,一旦发生回传,TextChanged事件也会被在页面生命周期的阶段appropriaate叫。

Using Update panel is fine and once postback happens, TextChanged event will be called too at appropriaate stage of page life cycle.

另外,尽量离开文本框code相同,但下降在UpdatePanel。换句话说,采取AJAX完全脱离,看看你的事件经常回发期间射击(当你期望它你得到回发)。这必将有助于缩小问题。

Also, try to leave the textbox code the same but drop the UpdatePanel. In other words, take AJAX completely out and see if your event is firing during a regular postback (and that you're getting the postback when you expect it). This will surely help narrow down the problem.

在的情况下,您希望此事件,火灾,每次击键动作制作(如你输入),这将有助于:<一href=\"http://stackoverflow.com/questions/1009086/how-to-make-an-asp-net-textbox-fire-its-ontextchanged-event-fire-in-an-ajax-upd\">How使一个ASP.NET的TextBox火它onTextChanged火灾事件在AJAX的UpdatePanel?

In case, you want this event to fire, everytime a KeyStroke is made ( as you type in), This will help: How to make an ASP.NET TextBox fire it's onTextChanged event fire in an AJAX UpdatePanel?

这篇关于在asp.net中自动调用文本框TextChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆