update panels and javascript?

H

HockeyFan

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 execute a particular
javascript function (client-side). THis is supposed to work. I've
done it hundreds of times otherwise, but never in an update panel
(until now).
It doesn't work. I put an alert in the top of my javascript function,
and it never is executed. I made sure that script debugging was
enabled (or rather, not disabled). I get no error either on setting
the attribute, or when I click the check boxes on any of the rows in
the gridview.

So, how do people set up controls within an update panel, to execute
client-side code?
 
I

IfThenElse

In your browser View Source and see if you are getting your JavaScript
right.
This is how I do it and most of the time my View Source tells me what is
wrong in my JavaScript.

Make sure your ClientID(s) are correct.
There might be syntax errors in your JavaScript

Also set you Browser to always report JavaScript errors, you will be
surprised how many web pages out there with JavaScript errors that
programmers fail to see because there browser set up to NOT show errors.
 
B

bruce barker

the update panel does not support client events tied to the control via
html. this is becuase the browser doesnot support it: ex:

div.innerHTML = "<button onclick='doClick()'>click me</button>";

the onclick event handler will not be hooker, nor will inline script work:
div.innerHTML = "<script>alert('hi')</script>";

you will need to attach the onclick event via javascript the updatepanel
will run afterwards. using

ScriptManager.GetCurrent(Page).RegisterClientScriptBlock(Page,this.GetType(),"key1",
"$get('mycontrolid').onclick=doclick;",
true);

in this case, the script is sent down and the updatepanel code will do
an eval() of it.

of course in your case, you need to add one for for each row. the
databind would be handy for this, or your client script could walk the
dom and add the events.

-- bruce (sqlwork.com)
 
I

IfThenElse

Bruce,

good job,

can you use
ClientScript.RegisterClientScriptBlock( etc......)

what does ScriptManager.GetCurrent(Page). mean?



Thank u
 
B

bruce barker

just to confuse things there are two client managers.

Page.ClientScript is the builtin one for asp.net

ScriptManager is the new ajax script manager used to output script for
the ajax controls and the update panel. scriptmanager is an ajax control
you place on the page to make it ajax enabled.

ScriptManger.GetCurrent(Page)

searches the page for the actual scriptmanger control placed on the
page, so you don't need the name. handy inside of ajax aware control you
write.

script registered with the ClientScript, will not work with an async
postback via the update panel, you must use the ajax control. it actualy
includes the response payload, and client script on the page does an
eval of it.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top