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

x
?
Solved

Ajax, Render JavaScript inside Update Panel

Posted on 2007-08-09
8
Medium Priority
?
3,291 Views
Last Modified: 2013-11-05
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
Comment
Question by:jimmieandersson
  • 5
  • 3
8 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 19671930
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 19671962
If you start things out with

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

does it act any differently?
0
 

Author Comment

by:jimmieandersson
ID: 19672199
yes if I start with visible="true" on page_load it works perfectly fine.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Expert Comment

by:HonorGod
ID: 19672644
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
 

Author Comment

by:jimmieandersson
ID: 19673816
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
 

Author Comment

by:jimmieandersson
ID: 19673984
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
 
LVL 41

Accepted Solution

by:
HonorGod earned 1500 total points
ID: 19674077
Excellent.  Glad to hear it.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 19680260
Thanks for the points.  Good luck
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 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