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

RegisterClientScriptBlock problem

I have used RegisterClientScriptBlock in my ASP.NET page. it works well. Here I have problem. When Postback occurs, I dont want the script to be emitted. But It emits the Script even if I dont call the RegisterClientScriptBlock

How to prevent this?
Nov 18 '05 #1
6 6195
if(!Page.IsPostback)
{
string strClientScriptIdent = "xyz";
if(!Page.IsClientScriptBlockRegistered(strClientSc riptIdent)
{
string strClientScript = "blah blah blah";
Page.RegisterClientScriptBlock(strClientScriptIden t,
strClientScript);
}
}

--

Regards,

HD
"Rajan" <an*******@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
I have used RegisterClientScriptBlock in my ASP.NET page. it works well. Here I have problem. When Postback occurs, I dont want the script to be
emitted. But It emits the Script even if I dont call the
RegisterClientScriptBlock.
How to prevent this?

Nov 18 '05 #2
Thanks for you reply. But my problem is little different
Let me explain the scenario to you
when I click on the button "A", I want the focus to be set to "TEXT1". So I call RegisterClientScriptBlock method to set the focus using javascript". it works fine
When I click on Button "B" in the same page I dont want to do anything regarding focus, so I didnt call RegisterClientScriptBlock methed this time
But still the Page persists the javascript which was previously emitted and set the focus to "TEXT1" which I dont want
How to remove the script which was emitted at the first tim

Thanks.
Nov 18 '05 #3
you dont need to mess about with the registerclient script.
instead of OnClick="javascriptfunction();"
use object.attibutes.add("onClick", "javascriptfunction();");
that way you only add the attributes for objects you want to have client
events.

--
Regards,
HD
Once a Geek.... Always a Geek
"Rajan" <an*******@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.com...
Thanks for you reply. But my problem is little different.
Let me explain the scenario to you.
when I click on the button "A", I want the focus to be set to "TEXT1". So
I call RegisterClientScriptBlock method to set the focus using
javascript". it works fine.
When I click on Button "B" in the same page I dont want to do anything
regarding focus, so I didnt call RegisterClientScriptBlock methed this
time.
But still the Page persists the javascript which was previously emitted
and set the focus to "TEXT1" which I dont want.
How to remove the script which was emitted at the first time

Thanks.

Nov 18 '05 #4
Since I have to use this in lot of places (not only in button clicks) I have come up with the generic function like the one in below which emits javascript

public void SetFocusControl(string ControlName

string script = "<script language=\"javascript\"> var control = document.getElementById(\""
ControlName + "\");" + " if( control != null ){control.focus(); if(control.type == 'text') control.select();}" +
"</script>"
Page.RegisterStartupScript("Focus", script)
So whenever I want to set the focus to particular control I would call this fuction with that control name
when I dont want I dont call this, still the Page emits the javascript which was emitted at the last time
So I want to remove that script. is there any way to remove the registered script using the key or in some other way

Thanks
Nov 18 '05 #5
nope. i dont think there's a method to remove the registered script.
as a work around you could overwrite it to a emtpy javascript function or
something like that... or try just over writing it with ""
not sure whether it will work but its worth a try.

--
Regards,
HD
Once a Geek.... Always a Geek
"Rajan" <an*******@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
Since I have to use this in lot of places (not only in button clicks) I
have come up with the generic function like the one in below which emits
javascript.

public void SetFocusControl(string ControlName)
{
string script = "<script language=\"javascript\"> var control =
document.getElementById(\"" +
ControlName + "\");" + " if( control != null ){control.focus();
if(control.type == 'text') control.select();}" +
"</script>";
Page.RegisterStartupScript("Focus", script);
}

So whenever I want to set the focus to particular control I would call
this fuction with that control name.
when I dont want I dont call this, still the Page emits the javascript
which was emitted at the last time.
So I want to remove that script. is there any way to remove the registered
script using the key or in some other way?

Thanks

Nov 18 '05 #6
Rajan wrote:
Since I have to use this in lot of places (not only in button clicks) I have come up with the generic function like the one in below which emits javascript.

public void SetFocusControl(string ControlName)
{
string script = "<script language=\"javascript\"> var control = document.getElementById(\"" +
ControlName + "\");" + " if( control != null ){control.focus(); if(control.type == 'text') control.select();}" +
"</script>";
Page.RegisterStartupScript("Focus", script);
}

So whenever I want to set the focus to particular control I would call this fuction with that control name.
when I dont want I dont call this, still the Page emits the javascript which was emitted at the last time.
So I want to remove that script. is there any way to remove the registered script using the key or in some other way?

Thanks

You must be calling this even when you think you're not. The script
blocks are maintained in an instance member of the Page class, so when a
new Page instance is created (which happens with each HTTP request) it
starts with an empty script block collection.

Set a breakpoint on the method, and you'll find the culprit.

--
mikeb
Nov 18 '05 #7

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

Similar topics

6
by: PatLaf | last post by:
Hello to all I have created an asp.net application that needs to view pdf documents. I ran into a security issue but I added the identity impersonate = true and turned off anonymous access to the...
2
by: sam | last post by:
I am trying to emit script to the response stream within the Application_Error handler in global.asax. I want to emit using Page.RegisterClientScriptBlock. This doesn't work, and I have been...
9
by: Wayne Wengert | last post by:
I am attempting to incorporate some techniques I found in an MSDN article into one of my aspx pages. It basically adds a new class that Inherits from the System.Web.UI.Page and includes some new...
1
by: Simon Harris | last post by:
Hi All, I'm trying to write a composite web control which will render a rich text editor. I am having problems with RegisterClientScriptBlock - The script simply doesnt get written. There are...
2
by: kewl | last post by:
Hi All, We have an ASP.NET 2.0 (C#) intranet application that needs to spawn multiple browsers using RegisterClientScriptBlock. Here's what we got so far: // Go thru each datarow in the...
9
by: Nathan Sokalski | last post by:
I have used the RegisterClientScriptBlock method in external functions of mine (ones that are saved in a separate *.vb file), where I use them as follows: Public Shared Sub MyFunction(ByVal...
1
by: Vivian | last post by:
I've created a web page with ASP .NET and C#. Say my aspx filename is "WebForm1.aspx", I have created another C# file named "Details.cs". My problem is I want to prompt an alert message from both...
1
by: deepa.ravikiran | last post by:
Escape characters in RegisterClientScriptBlock I am using the RegisterClientScriptBlock to emit client script. What I am trying to do here is: User can open a popup window to build an MS...
3
by: | last post by:
Hello, I try to open a new Window in code behind with : ClientScript.RegisterClientScriptBlock(this.GetType(), "MyOpenScript", "window.open('toto.doc');", true); My problem is that the new...
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?
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...

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.