tags:

views:

36

answers:

1

i am trying to figure out how to display message box after it done executing the server side code

here is the code which works from the client side but still looking for a way to make it work from code-behind

.aspx

<div id="status"></div> 

script:

$("#status").fadeTo(500, 1, function() { $(this).html("You are now registered!").fadeTo(7000, 0); })
A: 

Not sure why you are fading the status div twice.

I get it now. You are trying to show the div and then fade it away. Try this:

$("#status").html("You are now registered!").show().fadeTo(7000, 0);

Or you could use fadeIn and fadeOut to make them both fade, like this:

$("#status").html("You are now registered!").fadeIn(500).fadeOut(7000);

SERVER SIDE

To do it on the server side you would use the RegisterClientScriptBlock method of the ScriptManager class like so:

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "clientScript", "$(function() { $('#status').html('You are now registered!').fadeIn(500).fadeOut(7000); });", True)

The first parameter would be the page you are using it on. Then the type, which you can use me.GetType() to get, then a name for the method which isn't really important what you call it, and then the actual jQuery code. The last parameter is a boolean as to whether to include script tags or not. If you put them in the jquery code, set it to false, otherwise keep it true.

Also, you may need a ScriptManager control between the form tags on the page you use this on. And this was done using VB code.

ryanulit
how can i do it through code behind? (asp.net)
Abu Hamzah
Why won't ASP.NET WebForms just die already?! In all seriousness though, you shouldn't be putting javascript in your code behind.
Keith Rousseau
@ryanuliti know the client side works but i want to display from code behind as i have stated above.
Abu Hamzah
@Keith Rousseau: i know....i know....
Abu Hamzah
I agree with Keith as this is really ugly. There are "better" ways of doing code-behind to jQuery coding by using page methods (http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/), but still somewhat annoying.
ryanulit
Alright @Abu I had to make a few edits, but my final version is there now and should hopefully work for you.
ryanulit
its throwing me an error: Microsoft JScript runtime error: 'null' is null or not an object, i have div with the id="status"
Abu Hamzah
I just tried the code and it works for me. Are you sure jQuery is loading? If you are loading it in a master page, make sure you use <script type="text/javascript" src="<%= ResolveClientUrl("~/relative_path_to_jquery/jquery.js") %>"></script> to get the path right.
ryanulit