473,398 Members | 2,393 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,398 software developers and data experts.

Unregistering a script block

RSH
I have a situation where I am Registering a Startup script with the
following code:

If Not IsPostBack Then

Dim sScript As StringBuilder = New StringBuilder

sScript.Append("<SCRIPT language=""javascript"">" & vbCrLf)

sScript.Append("document.all.Contact_txtLoginUserN ame.focus()")

sScript.Append("</SCRIPT>" & vbCrLf)

Page.RegisterStartupScript("Window.OnLoad", sScript.ToString)

End if

The problem is that I am using two panels...one which contains the textbox
that I am adding focus to, but one the user logs in I am setting the
visibility of the panel that contains the txtLoginUserName = false, so now
on postback the page errors out because the control is not there. Is there
a way to unregister the script if isPostBack = true?

I already have the registerStartUpScript in the if Not IsPostBack check.

Thanks,

Ron
Jul 27 '06 #1
1 3991
Hi,

a method to unregister directly doesn't exist but you can for example do so
that put code on Page's PreRender (or specific control's Prerender) and
output the script only if the control is Visible.

'This code in PreRender of Page or the control.

If myControl.Visible Then

Dim sScript As StringBuilder = New StringBuilder

sScript.Append("<SCRIPT language=""javascript"">" & vbCrLf)

sScript.Append("document.all.Contact_txtLoginUserN ame.focus()")

sScript.Append("</SCRIPT>" & vbCrLf)

Page.RegisterStartupScript("Window.OnLoad", sScript.ToString)

End If
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"RSH" <wa*************@yahoo.comwrote in message
news:uH**************@TK2MSFTNGP04.phx.gbl...
>I have a situation where I am Registering a Startup script with the
following code:

If Not IsPostBack Then

Dim sScript As StringBuilder = New StringBuilder

sScript.Append("<SCRIPT language=""javascript"">" & vbCrLf)

sScript.Append("document.all.Contact_txtLoginUserN ame.focus()")

sScript.Append("</SCRIPT>" & vbCrLf)

Page.RegisterStartupScript("Window.OnLoad", sScript.ToString)

End if

The problem is that I am using two panels...one which contains the textbox
that I am adding focus to, but one the user logs in I am setting the
visibility of the panel that contains the txtLoginUserName = false, so now
on postback the page errors out because the control is not there. Is
there a way to unregister the script if isPostBack = true?

I already have the registerStartUpScript in the if Not IsPostBack check.

Thanks,

Ron


Jul 28 '06 #2

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

Similar topics

0
by: Les Caudle | last post by:
After removing the .NET Framework (so that I can install the 1.1 Framework), I get the following error msg in the event log: The description for Event ID ( 1071 ) in Source ( ASP.NET 1.0.3705.288...
6
by: Saso Zagoranski | last post by:
Hi! How can I unregister all the events registered to a control? I have seen a piece of code in another thread, which gets all the registered handlers for a specific event. Let's say I have a...
1
by: | last post by:
Hi all I am using RegAsm.exe to register .NET assemblies like this: regasm D:\...\...\MyDLL.dll /tlb:d:\mybin\MyDLL.tlb for unregistering: regasm D:\...\...\MyDLL.dll /tlb:d:\mybin\MyDLL.tlb...
17
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script...
3
by: Tobius | last post by:
I want to be able to define a custom onerror event that detects an attempt to call a known function and load a file if it's not already loaded and re-call the function. The only problem is that any...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because...
17
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
2
by: KBSTours | last post by:
Hi, I am using Page.ClientScript.RegisterStartupScript but couldn't find any way to unregister the registered script. Is there a way to do that? --
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.