473,396 Members | 1,987 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,396 software developers and data experts.

changing a registered client script block

Hi,

I have a client script block, which is registered in my Page_Load.

However a button may result in the need to change the script which I've
registered.

Obviously the OnClick event occurs after Page_Load, so calling
RegisterClientScriptBlock with the same key does nothing.

Unfortunately I have other buttons (inside custom web controls) which
cause postbacks but no changes to the script, which means I can't do
something like

if (!IsPostBack) CallMethodWhichCreatesAndRegistersTheScript();

in Page_Load

Nov 7 '06 #1
6 2887
A working, albeit possibly not a very elegant, solution is this:

1. do not register the script in the web form's Page_Load if IsPostBack
is true.

2. make sure the scope of the script generation/registration method is
public

3. call the method in each button's OnClick event

3.1. for buttons in custom controls, simply cast the Page object to
your web form so you can call the method.
ie MyWebForm page = (MyWebForm)Page;
page.ScriptCreationRegistrationMethod();

Cheers

Nov 7 '06 #2
Of course, this merely prevents the script from being registered until
we are assured that the version that we have is the version that gets
registered.

The question of changing an already registered script (if possible)
still remains, so if anyone has a suggestion, go wild :)

Nov 7 '06 #3
Instead of changing the script code, pass a parameter string from server to
client and get the script code to check the parameter to determine what to
do. Use a hidden input control to pass data 2-way between server and client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Velislav" <vg*****@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
Hi,

I have a client script block, which is registered in my Page_Load.

However a button may result in the need to change the script which I've
registered.

Obviously the OnClick event occurs after Page_Load, so calling
RegisterClientScriptBlock with the same key does nothing.

Unfortunately I have other buttons (inside custom web controls) which
cause postbacks but no changes to the script, which means I can't do
something like

if (!IsPostBack) CallMethodWhichCreatesAndRegistersTheScript();

in Page_Load

Nov 7 '06 #4
That sounds good, but I'm struggling to see how it would work in my
specific case.

I have a custom control, which (amongst other things) contains a
checkbox.

My button creates these custom controls on the fly and adds them to the
form.

The client-side script makes all the checkboxes mutually exclusive.
Which means all the checkboxes have to be created before I can do any
client-side manipulations on them, right?

How can I use a parameter string/hidden input to represent the
checkboxes the script will deal with? Just for curiosity's sake.

Eliyahu Goldin wrote:
Instead of changing the script code, pass a parameter string from server to
client and get the script code to check the parameter to determine what to
do. Use a hidden input control to pass data 2-way between server and client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
Nov 7 '06 #5
One possibility is to find the checkboxes on client side based on their id.
I gave just a general idea, could be in your particular case server-side
script emitting is justified.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Velislav" <vg*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
That sounds good, but I'm struggling to see how it would work in my
specific case.

I have a custom control, which (amongst other things) contains a
checkbox.

My button creates these custom controls on the fly and adds them to the
form.

The client-side script makes all the checkboxes mutually exclusive.
Which means all the checkboxes have to be created before I can do any
client-side manipulations on them, right?

How can I use a parameter string/hidden input to represent the
checkboxes the script will deal with? Just for curiosity's sake.

Eliyahu Goldin wrote:
>Instead of changing the script code, pass a parameter string from server
to
client and get the script code to check the parameter to determine what
to
do. Use a hidden input control to pass data 2-way between server and
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Nov 7 '06 #6
Hi,

Velislav wrote:
Hi,

I have a client script block, which is registered in my Page_Load.

However a button may result in the need to change the script which I've
registered.

Obviously the OnClick event occurs after Page_Load, so calling
RegisterClientScriptBlock with the same key does nothing.

Unfortunately I have other buttons (inside custom web controls) which
cause postbacks but no changes to the script, which means I can't do
something like

if (!IsPostBack) CallMethodWhichCreatesAndRegistersTheScript();

in Page_Load
It's easy to identify which button has been clicked according to the
Request.Form collection. The clicked button's ClientID's will be present
in the Form collection.

Ex:
If your button is bnExecuteForm, then:

(in OnInit)

if ( this.Request != null
&& this.Request.Form != null
&& this.Request.Form[ bnExecuteForm.ClientId ] != null )
{
// Register client script
}

I never quite understood why the controls' events occur so late in the
AS.NET chain of events...

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 7 '06 #7

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

Similar topics

3
by: sklett | last post by:
Hi- I understand that the Page class has methods for inserting client script into the page. I don't want to build my entire client block w/ a StringBuilder because I only need 1 dynamic...
7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
1
by: John Mason | last post by:
Hi, I am trying to figure out how to do a client-side calculation based on textbox values, using asp.net, without performing a postback. I have 2 textboxes... <asp:textbox runat="server"...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
3
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
5
by: Alex Maghen | last post by:
I frequently find myself wanting to insert some basic client-side JavaScript functions in the page of an ASPX of mine. But I find it so frustrating that I have to actually contruct my JavaScript in...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.