Solved

Problem with javascript and UpdatePanel

Posted on 2008-06-17
1
1,332 Views
Last Modified: 2012-06-21
I am having a problem with javascript, an UpdatePanel, and a textbox.   Basically, everything is working fine except that when the event from the textbox gets triggered, it does a full page reload instead of an ajax style update.  The code is below.  I can't seem to find the bug, hopefully someone here can.  this is the code which creates the update panel, the textbox and the events.  All i want this to do is every time someone something in the textbox, it refreshes the date.
TextBox box = new TextBox();
            box.ID = "box";
            box.TextChanged += new EventHandler(this.box_TextChanged);
            box.Attributes.Add("onKeyUp", "javascript:__doPostBack('box','')");
            
            AsyncPostBackTrigger boxtrigger = new AsyncPostBackTrigger();
            boxtrigger.ControlID = "box";
            boxtrigger.EventName = "TextChanged";
 
            UpdatePanel panel = new UpdatePanel();
            panel.ID = "UpdatePanel1";
            panel.ChildrenAsTriggers = true;
            panel.UpdateMode = UpdatePanelUpdateMode.Conditional;
            panel.Triggers.Add(boxtrigger);
            panel.ContentTemplateContainer.Controls.Add(box);
            panel.ContentTemplateContainer.Controls.Add(new LiteralControl(DateTime.Now.ToString()));

Open in new window

0
Comment
Question by:Metsfan92286
1 Comment
 
LVL 14

Accepted Solution

by:
ajitha75 earned 125 total points
ID: 21809768
Is this residing inside a user control. One thing you wan to check is that ClientID and ID of box are same. If they are not, then you have to ensure that you pass the ClientId for the below assignment

box.Attributes.Add("onKeyUp", "javascript:__doPostBack('box','')");

you can change it to

box.Attributes.Add("onKeyUp", "javascript:__doPostBack('" + box.ClientID +"','')");
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now