Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

update panels and javascript?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HockeyFan - 16 Oct 2007 22:21 GMT
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?
IfThenElse - 16 Oct 2007 23:35 GMT
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.

> 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,
[quoted text clipped - 10 lines]
> So, how do people set up controls within an update panel, to execute
> client-side code?
bruce barker - 17 Oct 2007 00:46 GMT
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)

> 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,
[quoted text clipped - 10 lines]
> So, how do people set up controls within an update panel, to execute
> client-side code?
IfThenElse - 17 Oct 2007 01:01 GMT
Bruce,

good job,

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

what does ScriptManager.GetCurrent(Page).  mean?

Thank u

> the update panel does not support client events tied to the control via
> html. this is becuase the browser doesnot support it: ex:
[quoted text clipped - 34 lines]
>> So, how do people set up controls within an update panel, to execute
>> client-side code?
bruce barker - 17 Oct 2007 04:58 GMT
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)

> Bruce,
>
[quoted text clipped - 45 lines]
>>> So, how do people set up controls within an update panel, to execute
>>> client-side code?
IfThenElse - 17 Oct 2007 16:04 GMT
Bruce,

Excellent, Thank you for taking the time to explain,

well done.

> just to confuse things there are two client managers.
>
[quoted text clipped - 66 lines]
>>>> So, how do people set up controls within an update panel, to execute
>>>> client-side code?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.