Systems bombs out trying to display error message rather than displaying error message

Hi

I am using the following method to display error messages in my
asp.net c# system:

currentPage.Controls.Add(new LiteralControl("<script
language='javascript'> window.alert('" + strMsg + "')</script>"));

However, at certain times this falls over with the message:

The control collection cannot be modified during DataBind, Init, Load,
PreRender or Unload phases

Is there a way round this, like maybe using a deferred message?

Stapes

0
stapes
12/17/2008 10:07:53 AM
asp.net.client-side 24353 articles. 2 followers. Follow

3 Replies
1704 Views

Similar Articles

[PageSpeed] 50

hi stapes,

Try using the ClientScriptManager to manage your javascript instead of adding it using a literal.

 

ClientScriptManager csm = Path.ClientScripts;

csm.RegisterClientScriptBlock(this.GetType(),"[UniqueIdentifier]","[JavascriptCode]",true);
//The last Parameter is wether or not it needs to add script tags to your code.

 

Hope this helps.


Happy Coding,

SyntaxC4

*** REMINDER ***
If you find this post useful, Please click the 'Mark as Answer' Button.

*** DISCLAIMER ***
All Code is provided AS IS.

** Want Some Useful Sites **

http://www.delicious.com/SyntaxC4
0
SyntaxC4
12/17/2008 9:11:25 PM

Thanks for your suggestion. It seems to put me into an infinite regress. I tried the following:

1. String csname2 = "MsgBox";

2. Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.

3. ClientScriptManager cs = Page.ClientScript;

 

// Check to see if the client script is already registered.

if (!cs.IsClientScriptBlockRegistered(cstype, csname2))

{

StringBuilder cstext2 = new StringBuilder();

cstext2.Append("<script type=\"text/javascript\"> window.alert('" + strMsg + "')</script>");

cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);

}

It won't compile. I get the following errors:

Error 1 Keyword 'this' is not valid in a static property, static method, or static field initializer C:\Projects\Autogas\AGwww\App_Code\Utilities\Utils.cs 75 27 C:\...\AGwww\  this refers to line no 2.

Error 2 An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.ClientScript.get' C:\Projects\Autogas\AGwww\App_Code\Utilities\Utils.cs 78 38 C:\...\AGwww\ - this refers to line 3

Help

0
stapes
1/12/2009 5:17:12 PM

Why do you have a duplicate post? Answered here: http://forums.asp.net/t/1370216.aspx

NC...

 

0
NC01
1/12/2009 5:42:54 PM
Reply:

Similar Artilces:

Strange Error: Reentrancy error: some client,attempted to display a message to the console while in a console,listener
Hi, I am not sure where to ask and so ask three mailing lists. First off, TB 38.0.1 after many months of waiting solved many outstanding issues, Great. I hope we can correct many remaining issues in the months ahead. I am testing full debug build of C-C TB locally. This is done by running |make xpcshell-tests| to run xpcshell unit tests. I have noticed a few new errors in the last week or so after the code has been refreshed. These errors/warnings are new additions and I am trying to eliminate them. A case in point. A strange error I have never seen before. PROCESS ...

Strange Error: Reentrancy error: some client,attempted to display a message to the console while in a console,listener
Hi, I am not sure where to ask and so ask three mailing lists. First off, TB 38.0.1 after many months of waiting solved many outstanding issues, Great. I hope we can correct many remaining issues in the months ahead. I am testing full debug build of C-C TB locally. This is done by running |make xpcshell-tests| to run xpcshell unit tests. I have noticed a few new errors in the last week or so after the code has been refreshed. These errors/warnings are new additions and I am trying to eliminate them. A case in point. A strange error I have never seen before. PROCESS ...

Strange Error: Reentrancy error: some client,attempted to display a message to the console while in a console,listener
Hi, I am not sure where to ask and so ask three mailing lists. First off, TB 38.0.1 after many months of waiting solved many outstanding issues, Great. I hope we can correct many remaining issues in the months ahead. I am testing full debug build of C-C TB locally. This is done by running |make xpcshell-tests| to run xpcshell unit tests. I have noticed a few new errors in the last week or so after the code has been refreshed. These errors/warnings are new additions and I am trying to eliminate them. A case in point. A strange error I have never seen before. PROCESS ...

My CompareValidator error message either always displays, or never displays
I am trying to use a CompareValidator control, but either it is not working or I am doing something wrong. I want the CompareValidator control to compare the (date) values of two TextData controls that each have a CalendarExtender (AJAX Control Toolkit) attached to them. The properties I set on the CompareValidator are: ControlToCompare = Box_StartDateControlToValidate = Box_EndDateDisplay = DynamicError Message = "You jive tom turkey! You are one sorry rascal!! Sit on a potato pan Otis. Remember the Alamo. Das fesche Umherstolzieren des Hahns ist ein bekannter Anblick. What would yo...

parser error :an error message appears instead of displaying the home page.
 reply your solutions as soos as possible pleasssssssssssssssssse Server Error in '/' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not load type 'W1.WebForm1'.Source Error: Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="W1.WebForm1"%> Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> L...

parser error :an error message appears instead of displaying the home page.
hi friendsthe error message is:  Server Error in '/' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not load type 'W1.WebForm1'.Source Error: Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="W1.WebForm1"%> Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> Line 3: <HTML>Source File...

succesfully installed butpermanently displays error message,and wont display anything at all.
Name: Derek West Email: dgwatderekwestdotmedotuk Product: eBay Companion Summary: succesfully installed butpermanently displays error message,and wont display anything at all. Comments: Dead Loss. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 From URL: http://en-gb.www.mozilla.com/en-GB/add-ons/ebay/feedback/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Where should I display the error messages?
Hi in every application there are always parts of code with error handling: Try doSomething() Catch ex as Exception .... End Try In a windows form application, I can display error messages in this way: msgbox(ex.tostring). In a webform application I'd like to have an error page to display errors. I'd like to pass it the error string and the page that have generated the error (so I can Include a "Back" link to return back). The question is: "where could I save the error message?". My idea is to save it in a Session variable, so I can read it...

Display Error Message
I have a formview with object data source. All my controls in the form, eg textbox, are one way binding. (meaning all my controls use <%# Eval("MyField") %> instead of using Bind() ) I realise that the formview and object data source have the following sequence of events :1. formview_ItemInserting2. objectdatasource_Inserting3. objectdatasource_Inserted4. formview_ItemInserted5. page_PreRender I do some validations in objectdatasource_Inserting event. When an exception is thrown, I cancel objectdatasource event in objectdatasource_Inserting : e.Cancel = true; Thus objectdatasour...

how to display an error message?
Right what I have at the moment is a page called licence.aspx which consisits of a formview which is linked to my database called licencerequests. on my form I have the following fields :SystemIDOrderIDRegistrationIDEmail Address Once I click on the button submit it will store the fields into the database table and show on a page called response.aspx, But I have a field called resultcode which is where i want an error to store if there is one i.e. Null value, Invalid Character.......etc instead of it goin off the program and onto the debugger i want it to store all the details including th...

Help Needed
Hi,        I am working vs.2008 and Framework 3.5.  I need a help to display the errors in model popup or some other methods.       Here is my web form details...  This is project delivery page.. When the user press the save button,  i am upload the delivery files to FTP.       FTP upload is a seperate thread... in this case FTP upload class throug the wrong FTP ID, User Name, Password..etc.. i am using TRY...CATCH.. after all the files upload....       How i will disp...

Catching Parser Error Message: Could not load file or assembly and display custom error page
Hi , Our Clients can work with only FileSystem website. And our Website application uses AJAX assemblies and references are added in the root web.config file. If our client doesnt have AJAX assemblies, we need to display custom error page which says to install ajax.  I have used Web.config Custom error tag. yes. it catches the error and But i get error because the page i redirected is come under this error web.config file.  Is there some other way to tackle this? Thanks, Sureshsekaran.  What exactly is the problem. Is it that on the error, u are not being red...

Display Dot Net Error messages in English (NON English OS)
HI,I have to use Japanese OS for asp.net development. I want to enable the error messages to display in english. Right now the error mnessages appear in Japanese. How to achieve the same. You can simply set the uiCulture attribute to english either in @page directive or config file, for example, put the following in <system.web> <globalization uiCulture="en-US" culture="en-US" /> 你好! Just FYI o_O Thanks a lot,It worked.Regards,senthil...

Some message headers display as underlined in message display pane
Hi -- I notice some of the message headers display as *underlined* in my message display pane and I'm not sure why. The subject, sender and Date fields all display as underlined. I think it happens for threads on which I've read *some* but not *all* of the messages. Is this normal behavior? Thanks. Rick wrote: > Hi -- I notice some of the message headers display as *underlined* in > my message display pane and I'm not sure why. The subject, sender > and Date fields all display as underlined. I think it happens for > threads on which I've read *so...

Web resources about - Systems bombs out trying to display error message rather than displaying error message - asp.net.client-side

List of mammals displaying homosexual behavior - Wikipedia, the free encyclopedia
For these mammals, there is documented evidence of homosexual behavior of one or more of the following kinds: sexual behavior , courtship , affection ...

Facebook Displaying Page Insights On Page Admins’ Personal Pages?
Some Facebook page administrators are seeing modules on their personal pages displaying page insights ad, campaign , and like totals for pages ...

Facebook Displaying Unread Messages from Pages in a New Updates Module
Facebook is displaying a new “Updates” sidebar module which shows some users unread messages sent to them by Pages. Users will see the Updates ...

Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air CNN Live - YouTube
Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air Lemon held up a Confederate flag first before holding up the sign. He asked, ...

Hazelwood coal mine fire: Morwell residents displaying symptoms similar to cigarette smokers, expert ...
An expert says some locals near Victoria's Hazelwood mine fire have symptoms similar to cigarette smokers.

Police accused of displaying fake G20 weapons
Toronto's top police officer misled the public by displaying fake weapons used in a medieval-themed role-playing game to help justify their actions ...

No charges for U.S. host for displaying high-capacity magazine on TV
NBC television journalist David Gregory won't face charges for displaying a high-capacity ammunition magazine on his "Meet the Press" news program ...

Jays' Escobar suspended three games for displaying slur
Toronto Blue Jays shortstop Yunel Escobar has been suspended three games for displaying a homophobic slur on his eye-black during a game on Saturday. ...

Google Play Store now displaying age-based ratings
We reported back in May that Google was adding age-based ratings to all apps in the Play Store as determined by the International Age Rating ...

Apple displaying Ferraris & other cars at WWDC hinting at CarPlay announcements
... 2014 Filed under: AAPL Company , iOS Continue reading more about AAPL Company and iOS at 9to5Mac . What do you think? Discuss "Apple displaying ...

Resources last updated: 12/20/2015 12:48:40 PM