Showing posts with label certain. Show all posts
Showing posts with label certain. Show all posts

Monday, March 26, 2012

Execute Javascript on each Page_Load

Hello all,

I have a piece of Javascript code that I need to execute after Page_Load according to a certain condition.

Now this Page_Load event is being fired using the Microsoft's AJAX Timer every 10 seconds. In the Page_Load I'm setting a value to a hidden field, so Javascript can check if to execute or not... (did I explained myself correctly?, I'm not quite good at it and at English).

How can I do this? If it can be done?

Thanks!!

I think u are on the right path. Just check the condition of the hidden field with the value u want it to have and if it satisfies execute the java script code by registering the script code.
so you mean I write the Javascript on that Page_Load by means of StringBuilder and then register it? Will it execute?
yes i mean that?you?create?a?script?block?through?a?string?builder?and?then?register?it?through?a?RegisterClientScript?Block.

I think if you paste your current code here may be i can help you much better way.

Here's how i do it;

Protected sub Page_Load(sender as object, e as eventargs) me.handles.load
JavaScript_Functions()
end sub

Private Sub JavaScript_Functions()

dim strScript as string = ""
strScript += "function dosomthing()"
strScript += "{"
strScript += " alert('hello world');"
strScript += " return false;"
strScript += "}"

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "JavaScript_Functions", strScript, true)
end sub

HTML
<asp:Button ID="btnTest" Text="Click Me" OnClientClick="return dosomthing();" runat="server" />

Saturday, March 24, 2012

Exceptions

Hi,I'm using webservices to get data from the server in my application, in certain circumstances I throw an exception that gets catched in the failed callback function in the client, and depending in the exception type a message is shown to the user, this works great when the browser and the server are in the same machine, but when I call the application from a different machine I get what I think is a default exception, with the message "There was an error processing the request." instead of my own exception, could someone tell me if this is by design, and if so how can I change this behavior so I can get my exceptions, or I'm doing something wrong here?

Thanks.

This is quite true when application is deployed with debugmode set false which we always do. Read the following article where I have shown an effective error logging in asp.net ajax.
http://dotnetslackers.com/columns/ajax/AspNetAjaxExceptionLogging.aspx


Thanks for the great article Kazi,I concord with you, the (some) exception information should be presented in the client side, I understand this is done for security reasons, but in my case for example I catch all exceptions in the webserver and log the relevant ones, and then only for some I throw a new exception to inform the user, for example when the user tries to save a duplicated record I catch the SqlException (this one doesn't need to be logged) and throw my own exception that tells the client application to show a message to the user telling him that there's all ready a record with that name in the database.


Yes, it should at least return the Exception message.


Hi,

In order to send real error message to the client side on a different machine, please turn CustomError off in web.config.


<customErrors mode="Off" />


Yes I have been forced to do that already, I really don't like it, but I need this for my implementation to work, fortunately I already catch all (I certainly hope so) the exceptions and only show the information I want in the client.