Updatepanel internal control updates "external" Control

Source: Internet
Author: User

Http://blog.csdn.net/huangkelong/article/details/2013466

 

ASP. net Ajax has a very magical and useful control updatepanel, which can help us easily achieve the non-synchronous PostBack function, let's. ajax technology can be directly added to the ASPX page.

Some readers often ask the author a question: Can I dynamically update the "control" outside updatepanel "in the events triggered in updatepabel?

Generally, when using updatepanel, you can set it as follows:

We usually put the "dynamic update in non-synchronous mode" Control in updatepanel. To update textbox1 in the screen, you only need to writeCode:

Protected sub button#click (byval sender as object, byval e as system. eventargs)
Me. textbox1.text = "..."
End sub

The click event triggered by button1 in updatepanel is executed in non-synchronous PostBack mode. Therefore, when the backend event click is executed, the value in textbox1 can be updated, the page does not need to be changed (submit ).

However, if you have used updatepanel for a long time, you will find that we cannot put all the controls in updatepanel. If you need to dynamically update the content of controls other than updatepanel in non-synchronous PostBack, what should we do? For example:

To update the content of the Control located outside updatepanel after clicking the button in updatepanel, use the tips of dynamic render javascript:

Protected sub button#click (byval sender as object, byval e as system. eventargs)
Dim JS as string
JS = "$ get ('textbox1'). value = '...';"
Scriptmanager. registerstartupscript (Me, GetType (string), "", JS, true)
End sub

In this way, you can use the dynamically generated JavaScript to update the controls that are placed outside the updatepanel on the front-end page.
In fact, this tip is quite useful. We can also use it to dynamically generate an alert window in the non-synchronous PostBack process. For example:

Protected sub button#click (byval sender as object, byval e as system. eventargs)
Dim JS as string
JS = "alert ('alert window generated during non-synchronous PostBack ...');"
Scriptmanager. registerstartupscript (Me, GetType (string), "", JS, true)
End sub

I hope this tips will help you with Ajax technology...

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1870893

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.