[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1342
  • Last Modified:

Problem with javascript and UpdatePanel

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
Metsfan92286
Asked:
Metsfan92286
1 Solution
 
ajitha75Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now