• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3298
  • Last Modified:

Ajax, Render JavaScript inside Update Panel

I use a javascript to "auto complete" text boxes when typing
It connect itself to a textbox by document.getElementById('" + tbxTwo.ClientID + "')

this works well if the text box is rendered in Page_Load
But if I inside a UpdatePanel, presses a button to get the Text Box and the javascript, it will not work.

I can understand why, probably doesn't the web browser render the javascript code inside the update panel after postback.

how do I solve this?

My example is here: http://dev.brightville.com/temp/javascript.aspx

and the code for this example is here:
aspx: http://www.aspsidan.se/code/default.asp?c=7723
code behind: http://www.aspsidan.se/code/default.asp?c=7724
0
jimmieandersson
Asked:
jimmieandersson
  • 5
  • 3
1 Solution
 
HonorGodSoftware EngineerCommented:
It appears like the code that is returned when the form is submitted doesn't have the keypress event handler defined.  The code that gets returned (for the second input field) should include the associated eventHandler to process the keys as they are pressed.
0
 
HonorGodSoftware EngineerCommented:
If you start things out with

<asp:Panel ID="pnlTwo" runat="server" Visible="true">

does it act any differently?
0
 
jimmieanderssonAuthor Commented:
yes if I start with visible="true" on page_load it works perfectly fine.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
HonorGodSoftware EngineerCommented:
wow, that's very strange.  It is as though the invocation of the BtnTwo_Click function is doing more than just making that panel visible.

I'm sorry, but I know very little about ASP.NET, so I'm not sure what is happening.
0
 
jimmieanderssonAuthor Commented:
its seems like the javascript block set to ltlTwo is not rendered in web browser after postback in the update panel.

someone told me that the update panel doesn't read the <script> block and that I have to use ScriptManager.RegisterClientScriptBlock but I don't know how to do that.
0
 
jimmieanderssonAuthor Commented:
I solved it!

        protected void BtnTwo_Click(object sender, EventArgs e)
        {
            string script = "var obj = actb(document.getElementById('" + tbxTwo.ClientID + "'),customarray);";

            ScriptManager.RegisterClientScriptBlock(uppSecond, this.GetType(), "init", script, true);
            pnlTwo.Visible = true;
        }

0
 
HonorGodSoftware EngineerCommented:
Excellent.  Glad to hear it.
0
 
HonorGodSoftware EngineerCommented:
Thanks for the points.  Good luck
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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