单击按钮时触发文本更改事件
我正在开发 .net 2.0,我正在使用多个文本框填充网格视图。文本框有文本更改事件。还有一个带有点击事件的按钮。我面临的问题是,当我在文本框中输入文本然后单击按钮时,文本更改事件被触发,并且执行不会到达按钮单击块。当两个事件都被触发时,如何检测按钮是否被单击。
有一个文本框,可以调用文本更改事件的函数
<asp:TextBox ID="txtChassis" runat="server" CssClass="form_text_box" AutoPostBack="true" OnTextChanged="Chassis_TextChanged"></asp:TextBox>
,也可以调用按钮单击事件的函数。
<input class="form_button" id="btnSearch" title="Show Details" accesskey="S" type="submit"
value="SAVE" name="btnSave" runat="server" onserverclick="btnSearch_ServerClick"/>
但是,如果将文本放置在文本框中并单击按钮,则会调用文本更改事件函数。
I am working on .net 2.0 I am populating a Grid View with multiple textboxes. The textbox has text change event. There is also a button with click event. The problem I am facing is that when the I enter the text in textbox and then click on button, the text change event gets fired, and the execution does not come to button click block. How can I detect if button has been clicked when both the events are fired.
There is the textbox with call to function for text change event
<asp:TextBox ID="txtChassis" runat="server" CssClass="form_text_box" AutoPostBack="true" OnTextChanged="Chassis_TextChanged"></asp:TextBox>
and also call to function for button click event.
<input class="form_button" id="btnSearch" title="Show Details" accesskey="S" type="submit"
value="SAVE" name="btnSave" runat="server" onserverclick="btnSearch_ServerClick"/>
However, in case text is placed in textbox and button is clicked, then the text change event function gets called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是,ASP 中的事件仅在回发后引发。
如果按下按钮,则回发会发生,并且客户端回发(名称)他的字段数据。
在此回发之后,服务器(您的应用程序)将调用上次 Page_Load 期间发生的所有事件。
据我所知,事件的抛出没有真正的顺序,但无论如何都应该抛出 textChanged 事件。
如果您想在文本更改后直接传递 textChanged 事件,则必须使用“AutoPostBack”,正如 Myat Thu 已经提到的那样。请注意,这会显着增加您的流量,并且还会改变代码的流量!
我建议设计独立的事件,以便用户可以点击“回发按钮”,并且所有事件都会在一次回发时调用。这可以节省服务器上的流量和负载。
但这只是我个人的意见。
Your Problem is, that events in ASP are only raised after a PostBack.
The Post back happens if the Button is pressend, and the Client Posts Back (therfor the Name) his Data of the Fields.
After this PostBack the Server (your application) calls all events that happend during the last Page_Load.
As far as i know, there is no real order in which the events are thrown, but the textChanged event should be thrown anyway.
If you want to hand your textChanged event directly after the Text hast changed you have to use "AutoPostBack" as Myat Thu already mentioned. Be aware that this increases your traffic signifficant, and can also change the flow of your code!
I suggest designen the events indipendet so the user can hit the "PostBack Button" and all events are called at one post back. This saves traffic and load on the server.
But this is just my personal oppinion.
您正在为窗口应用程序或 Web 应用程序编写代码吗?如果您正在为 Web 应用程序编写内容,则 TextBox 的属性如下:
您应该为您的 TextBox 对象尝试这两个属性。
Are you writing code for a window application or a web application? If you're writing for a web application, there are properties for TextBoxes which are:
You should try out both of these properties for your TextBox object.