简体   繁体   English

为文本框和AJAX更新面板控件创建事件

[英]Creating an event for a textbox and AJAX Update Panel Control

I wanted to create a "Click" event for a textbox in C# (as there isn't any). 我想为C#中的文本框创建“点击”事件(因为没有)。

So, this way 所以这样

protected void Page_Load(object sender, EventArgs e)
{
    if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "txt1OnClick")
    {
        txt1_Click();
    }

    txt1.Attributes.Add("onclick", this.Page.ClientScript.GetPostBackEventReference(txt1, "txt1OnClick"));
}

private void txt1_Click()
{
    ImageMap1.ImageUrl = "guide/1.jpg";
}

Then I wanted to load the image without reloading the page. 然后,我想加载图像而不重新加载页面。

So I used the AJAX UpdatePanel Control and this worked fine with 因此,我使用了AJAX UpdatePanel控件,并且在

protected void Button1_Click(object sender, EventArgs e)
{
    ImageMap1.ImageUrl = "guide/1.jpg";
}

But not with the event I created, because the compiler doesn't identify my new events as a real event or something I couldn't figure out. 但是,与我创建的事件无关,因为编译器无法将我的新事件识别为真实事件或无法确定的事件。

I added the button1_click event according to Step 8 of " Refreshing an UpdatePanel Control with an External Button ". 我根据“ 使用外部按钮刷新UpdatePanel控件 ”的步骤8添加了button1_click事件。

The click event of textbox is not shown in this option: 文本框的单击事件未显示在此选项中:

文本框

So my question is is there any way to add this event within System.Web.UI.WebControls.TextBox class or, to make this event visible within the above option? 所以我的问题是,有什么办法可以在System.Web.UI.WebControls.TextBox类中添加此事件,还是可以在上述选项中使此事件可见?

So that I can include click event of the textbox within the Triggers of the update panel. 这样我就可以在更新面板的“触发器”中包含文本框的click事件。

If you try to create a Click event for a TextBox , every time a user clicks your textbox you'll trigger a postback to the server (even to evaluate if you need to do something as part of handling the event). 如果您尝试为TextBox创建Click事件,则每次用户单击您的文本框时,都会触发回发到服务器(甚至评估是否需要在处理事件时做一些事情)。 This is very inefficient - you should handle clicks in the browser, using JavaScript and then trigger the UpdatePanel using client-side logic. 这是非常低效的-您应该使用JavaScript处理浏览器中的点击,然后使用客户端逻辑触发UpdatePanel。

This lets you trigger a call to the server if you need it but avoid it when you don't. 这使您可以在需要时触发对服务器的调用,但在不需要时避免调用。 If you have a server-side event handler, your code will post back to the server (reloading the page) every time the user clicks the TextBox . 如果您具有服务器端事件处理程序,则每次用户单击TextBox时,您的代码都会回发到服务器(重新加载页面)。

You can read this link (and others) about using __doPostBack() on the client side to trigger an UpdatePanel to perform a postback. 您可以阅读有关在客户端使用__doPostBack()触发UpdatePanel执行回发的链接(及其他链接)。

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/ http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ajax更新面板控件问题 - ajax update panel control issue 如何将带有事件处理程序的控件动态添加到更新面板,以及如何通过AJAX将事件处理程序回发 - How to add a control with an event handler dynamically to an update panel and have the event handler post back via AJAX 文本框ontextchanged事件在更新面板中触发,但在客户端抛出错误 - textbox ontextchanged event is firing in update panel but throws error on client side 在AJAX更新面板中将焦点设置为动态添加控件 - Set Focus on Dynamically added control in AJAX Update Panel 更新面板内的 AJAX 评级控制导致重新加载完整页面 - AJAX rating control inside update panel leads to reload the complete page 更新面板上的按钮单击事件未在多个用户控件中触发 - button click event on update panel not firing in multiple user control 带有.net日历控件的更新面板出现异步触发器和VisibleMonthChanged事件问题 - Update panel with a .net Calendar control having issues with asynctriggers & VisibleMonthChanged event 回发后重新绑定控件后,更新面板中的事件未触发 - Event in Update panel is not fired after rebinding control after Postback GridView超链接单击事件刷新Ajax更新面板 - Gridview hyperlink click event refresh ajax update panel 1.4.609更新后,Ajax Combobox无法再找到TextBox控件 - Ajax Combobox can no longer find TextBox control after update 1.4.609
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM