473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
RegisterClientS criptBlock 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) CallMethodWhich CreatesAndRegis tersTheScript() ;

in Page_Load

Nov 7 '06 #1
6 2907
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.ScriptCrea tionRegistratio nMethod();

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.goo glegroups.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
RegisterClientS criptBlock 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) CallMethodWhich CreatesAndRegis tersTheScript() ;

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.goo glegroups.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
RegisterClientS criptBlock 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) CallMethodWhich CreatesAndRegis tersTheScript() ;

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.Fo rm != null
&& this.Request.Fo rm[ bnExecuteForm.C lientId ] != 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
1952
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 variable in the whole block. So, with that said, here is what I need to do: <script language="javascript"> var root = <%=m_root%>;
7
7770
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 file such as MyNewScript.js and then cache that on the client so all the pages of that session can use it. Can this be done? Thanks -- moondaddy@nospam.com
3
1979
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 before the page is changed? I want to say that because the values are changed but the page is never reloaded after the change, that these changes do not take effect before the server.transfer. Please let me know if I am correct here. I think I am...
1
4655
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" CssClass="ddclass" ID="txtTotal" onBlur="calculate()" />
7
3213
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 think the username can be read with user.identity.name.
3
7726
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 value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
13
3030
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 and the put the data into an array in the post.... anywhat. I have a link <a href="javascript:change_class()" >Block mode</a> to
5
2224
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 C# on the server-side and render it to the client because I can't use the IDs of my controls as they are written in the HTML page itself. Rather, I have to use Control.ClientID to get that ID that I can use in the client-side JS. So my...
1
4532
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 want only one instance of the FCKEditor on the screen at one time so I make tabs that the user can click and I store the values in variables behind the scenes. I change the CSS class on the link that is the currently selected one. I have a really...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.