473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Having trouble injecting Javascript in AJAX enabled page withRegisterClientScriptBlock

Greetings,

I've been at this problem for some time now and have decided to seek
out some help.

Essentially, this is what I have. A basic ASP.NET 2.0 page. On this
page is the standard <formtag. Under that, we have an UpdatePanel
object where the rest of my partial rendering controls live. There is
simply a basic control, such as a Literal or Label in the
UpdatePanel. When a button is clicked on the page, I want to send out
Javascript back to the Label or Literal (set the Text property of this
control with javascript) such as "<script>alert('hello');</script>"

The problem? Whatever I send to the control gets there but nothing is
ever executed.

So, I have started trying RegisterClientScriptBlock() on the top level
"Page" object and even at the inner control level.

Nothing seems to happen.

If I inject javascript in the "Page_Load" method, it runs and works.
However, I need to inject javascript at a later time after the page
loads (since this is AJAX).

Does anyone have any words of advice? Anyone that has been down this
road? I sure would appreciate some help.
Jun 27 '08 #1
2 1643
I got it.

Use the STATIC method "RegisterClientScriptBlock" instead of the
ClientScriptManager for a control.

Something like this will work globally:

Microsoft.Web.UI.ScriptManager.RegisterClientScrip tBlock(UpdatePanel1,
typeof(UpdatePanel),“TestKey”, “alert(’Test’);“, true);

Two days wasted but now I feel better.
Jun 27 '08 #2
you server injected client to be render from a update panel postback,
you code needs to call the ScripManager.RegisterClientScriptBlock and
this call must be from a control inside the update panel. this is
because only html/script rendered inside the update panel is returned to
the client.
-- bruce (sqlwork.com)
Cr***********@gmail.com wrote:
Greetings,

I've been at this problem for some time now and have decided to seek
out some help.

Essentially, this is what I have. A basic ASP.NET 2.0 page. On this
page is the standard <formtag. Under that, we have an UpdatePanel
object where the rest of my partial rendering controls live. There is
simply a basic control, such as a Literal or Label in the
UpdatePanel. When a button is clicked on the page, I want to send out
Javascript back to the Label or Literal (set the Text property of this
control with javascript) such as "<script>alert('hello');</script>"

The problem? Whatever I send to the control gets there but nothing is
ever executed.

So, I have started trying RegisterClientScriptBlock() on the top level
"Page" object and even at the inner control level.

Nothing seems to happen.

If I inject javascript in the "Page_Load" method, it runs and works.
However, I need to inject javascript at a later time after the page
loads (since this is AJAX).

Does anyone have any words of advice? Anyone that has been down this
road? I sure would appreciate some help.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: RC | last post by:
Is AJAX built on top of JavaScript? What browsers supported AJAX? Can someone tell me some link introduce about AJAX?
8
by: Taras_96 | last post by:
Hi everyone, We' ve come to the conclusion that we wish the user to be directed to an error page if javascript is disabled <enter comment about how a webpage shouldn't rely on javascript here :)...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
5
by: HockeyFan | last post by:
We have an update panel that has a gridview with checkboxes and other items in each row. We went to the RowCreated event in the codebehind, to set an attribute on a checkbox in each row, to...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
15
by: Prisoner at War | last post by:
Okay, I think I'll soon be getting all the JavaScript/CSS/DHTML- related "site mechanics" wrapped up...at least until I decide on real Ajax-style interactivity next year! But until then, I'd be...
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
1
by: Constantine AI | last post by:
Here is the situation i am currently trying to update a sales order using PHP and javascript. When you click on the edit button it brings you a new site page with existing sales order details within....
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.