Solved

Problem with javascript and UpdatePanel

Posted on 2008-06-17
1
1,329 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

14 Experts available now in Live!

Get 1:1 Help Now