I want to use Thickbox (or one of the varieties) on our site to display information messages returned from the server. Examples include warning messages returned from biz logic, etc.
The first place to need this functionality will be the navigation buttons on an asp:wizard control. When the user tries to move forward, we validate their product selections and may have messages we need to display.
For testing, since I'm new to JQuery and Thickbox, I created a test page. The relevant part is below:
<asp:Panel runat="server" ID="pnl" Visible="false" style="display:none;background-color:Black;">
<div style="background-color:Black; width=300; height=200; ">
<asp:Label runat="server" ID="lblMessage" ForeColor="White" />
<script language="javascript" type="text/javascript">
function showMessage()
{
tb_show("Message", "#TB_inline?height=200&width=300&inlineId=<%# me.pnl.ClientID %>", null);
}
$(document).ready(function() { showMessage(); });
</script>
</div>
Currently, I get the Thickbox to display in IE7, but it's doubled. I get two vertical Thickboxes stacked together, both with title and close buttons, only the top one has my content.
In Chrome, the window gets the grayed out background, but no thickbox window is visible.
When I wrap the whole thing inside an AJAX UpdatePanel, I get nothing.
What am I doing wrong?
Kevin
OK, so more info. I've gotten both Thickbox and another one called LightView to sort of work. The following script block is static in the page (Thickbox version):
<script type="text/javascript" language="javascript">
function showMessage(sender, args)
{
tb_show("Message", "#TB_inline?height=200&width=300&inlineId=ctl00_ctl00_cph1_cphMain_pnl", null);
}
function StartWatch() {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(showMessage);
}
The postback sets the text of the label, which is inside the div specified in the call to tb_show. I get that the prm.add_endRequest call needs to be invoked before the postback fires.
There's several problems. First, entirely too much of this is hardwired -- an asp:panel and label in the page, the ID of the div spelled out, etc.
What we really want is to be able to invoke this from any code behind in some fashion like:
Page.ShowMessage("Hello lightbox!")
I'm thinking I could have some script and a DIV contained in the master page file. It would be hidden until invoked.
However, I need to be able to:
a) control when this happens. Not every AJAX request (in fact, most will not) need to have a message displayed when it returns. So, I would either not have to invoke the endRequest method, or have the endRequest method check something that comes back from the AJAX call to determine whether it really needs to call showMessage().
b) I'll need to find a way to have the UpdatePanel contain something with the message. If I could execute a line of JavaScript that would update a hidden or set the content of the hidden message DIV BEFORE the call to showMessage(), I think we'd be good to go.
The thickbox addin uses JQuery, the Lightview uses prototype and scriptalicous. Lightview is much fancier -- better images, animation, etc. I don't really care which.
I'm using the AJAX (Atlas) framework built into .NET.
Any advice on how to proceed would be appreciated.