Welcome Guest Search | Active Topics | Sign In | Register

Display JavaScript Popup Options
Michael Smit
Posted: Tuesday, June 3, 2008 8:30:50 AM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Hi,

How do I display a JavaScript popup when a CallBackPanel has completed updating.

Prior to the CallBackPanel, we were using the popups to display status messages to the user. Now we are wrapping the pages up in the CallBackPanels, the popups have stopped working and I cannot figure out how to get them working.
We are using a simple JavaScript alert method.
eo_support
Posted: Tuesday, June 3, 2008 8:34:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Hi,

You can put a Label inside the CallbackPanel and then set the Label's Text to something like this:

Label1.Text = "<script type='text/javascript'>window.alert('hi!');</script>";

The key is your JavaScript code has to be rendered inside the CallbackPanel. The usually way of RegisterClientScriptBlock won't work.

Thanks
Michael Smit
Posted: Tuesday, June 3, 2008 8:40:33 AM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Is there no way I can use the CallBackPanels ClientSideAfterUpdate event to show an alert box?
eo_support
Posted: Tuesday, June 3, 2008 10:26:54 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Sure you can. You would just call window.alert there. You may want to handle the CallbackPanel's Execute event to pass some parameter to the ClientSideAfterUpdate so that you can code your window.alert based on that data.
Michael Smit
Posted: Tuesday, June 3, 2008 10:30:17 AM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Are you able to provide a sample of using the two events to speed things up please.
Ex: User searched for operators. Operators name is input in a textbox and the search button is clicked. The CallBackPanel posts the request back to the server, and if no operators are found that match the search string the message "No operators could be found that matched the entered search critieria".
eo_support
Posted: Tuesday, June 3, 2008 11:02:17 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Hi,

The easiest way for you is to use a Label to render JavaScript as our original reply:

Code:
private void SearchButton_Click(object sender, EventArgs e)
{
    //function NoOperatorsFound checks user input
    if (NoOperatorsFound())
         Label1.Text = "<script type='text/javascript'>window.alert('No operators...');</script>";
}


You can use CallbackPanel's Execute event and ClientSideAfterUpdate. But it probably has no apparent benefit in your case (it won't really speed things up):

Code: C#
private void Callback1_Execute(object sender, CallbackEventArgs e)
{
    if (NoOperatorsFound())
    {
       //Pass this data to the client side so that client side
       //after update handler will know that "No operators has found"
       e.Data = "no data";
    }
}


Code: JavaScript
function after_update_handler(callback, output, extraData)
{
   if (extraData == "no data")
   {
       //e.Data in Callback.Execute is passed through extraData  
       //here. So we check the value to see if we need to display
       //the error message
       window.alert("No operators ....");
   }
}


Hope this helps.

Thanks
Michael Smit
Posted: Tuesday, June 3, 2008 11:09:07 AM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Thanks... Option 2 using the handers might not be faster, but at least I can set the after_update_handler script in the master page and save myself putting a label on every single form that uses the CallBackPanel (over 100 of them).
Michael Smit
Posted: Tuesday, June 3, 2008 12:16:00 PM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Another question... Hope I can post in the same thread.

I am trying to AJAX enable all pages for all post backs. I am finding having to add a CallBackPanel to every single page and then set triggers to each and every control that posts back to be very time consuming.

Is there a way to embed a CallBack control in the master page, and have it automatically handle all controls in the content place holder?
eo_support
Posted: Tuesday, June 3, 2008 12:20:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
You can set the parent control as a trigger. For example, you can set a Panel as a trigger instead of setting every buttons inside the Panel as a trigger.
Michael Smit
Posted: Tuesday, June 3, 2008 12:27:43 PM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
I have place a panel around the content place holder in the master page, then in the page that inherits from the master page, put a button in the CPH with a label and the button simply sets the current date time. Not working for me though, but no errors either...

Master page
<asp:Panel runat="server" ID="MainPanel">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</asp:Panel>
<eo:Callback ID="Callback" runat="server"
Triggers="{ControlID:MainPanel;Parameter:}">
</eo:Callback>

Test page using master
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder1">
<asp:Button ID="ClickMeButton" runat="server" onclick="ClickMeButton_Click"
Text="Click Me" />
&nbsp;<asp:Label ID="DateTimeLabel" runat="server"
Text="Click 'Click Me' to see the current Date and Time"></asp:Label>
</asp:Content>


Can you tell me what I am doing wrong here?
Code Monkey
Posted: Tuesday, June 3, 2008 12:28:43 PM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2008
Posts: 37
eo_support wrote:
You can set the parent control as a trigger. For example, you can set a Panel as a trigger instead of setting every buttons inside the Panel as a trigger.


Hope you don't mind if I pop in here, but I wanted to add a little to the conversation.

First, it never occured to me that I could set a parent control as the trigger - Thanks.

Second, a panel probably won't cut it because it doesn't implement INamingContainer.

When I was recently working with the CallBackPanel I really had wanted a simple panel control that implemented INamingContainer so that the only trigger I'd have to add would be the panel, but I wasn't able to find one and I didn't really want to roll my own just for one page. For many pages I'd probably reconsider and create a panel that does implement it though, which might be your case Michael.
eo_support
Posted: Tuesday, June 3, 2008 12:43:14 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Code Monkey wrote:
Second, a panel probably won't cut it because it doesn't implement INamingContainer.


Thanks for pointing that out. Panel indeed won't work because it does not implement INamingContainer.

Back to Michael question, what was implied is that the ContentPlaceHolder itself can be used as a trigger (because it's the parent of of the contents and it does implement INamingContainer). You won't see it in the trigger's ControlID drop down though. Just type it in there.
Code Monkey
Posted: Tuesday, June 3, 2008 12:46:08 PM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2008
Posts: 37
Aha! Wish I would have thought of that! I'll keep that in mind in the future, thanks :)
Michael Smit
Posted: Tuesday, June 3, 2008 12:46:31 PM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Well you guys simply rock!!! Works like a BOMB!!!

For those that might need to do this, here goes...

First subclass Panel...

namespace Savitar.Web.UI.WebControls
{
[ToolboxData("<{0}:Panel runat=server></{0}:Panel>")]
public class Panel : System.Web.UI.WebControls.Panel, INamingContainer
{
}
}

Setup Master Page
<eo:CallbackPanel ID="CallbackPanel" runat="server"
LoadingDialogID="LoadingDialog" Triggers="{ControlID:MainPanel;Parameter:}"
UpdateMode="Self">
<Savitar:Panel ID="MainPanel" runat="server">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</Savitar:Panel>
</eo:CallbackPanel>

Then do whatever you need to in your asp.net page
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder1">
<asp:Button ID="ClickMeButton" runat="server" onclick="ClickMeButton_Click"
Text="Click Me" />
&nbsp;<asp:Label ID="DateTimeLabel" runat="server"
Text="Click 'Click Me' to see the current Date and Time"></asp:Label>
</asp:Content>

Works just as expected and now I don't have to do a single thing to any of the 100 odd pages in the site. My client is already so happy with what I have done re AJAX on the site, they have offered to pay double rate to the end of the week to incentivise us to get the entire site done.
EO - you have just paid for yourself over and over and over in one week :)
Michael Smit
Posted: Tuesday, June 3, 2008 12:47:49 PM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Damn, so I can dump my quick and dirty little panel here :)

This CallBack panel is by far the easiest way to implement AJAX, yet earns such credibility with the clients :)
Ria
Posted: Sunday, June 8, 2008 2:00:00 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
Hello, I try your code,
made the subclass in my library
imports it in my masterpage
although i get the message: Unknown servertag Savitar
hope you can help me
Michael Smit
Posted: Sunday, June 8, 2008 3:19:47 AM
Rank: Member
Groups: Member

Joined: 6/6/2007
Posts: 19
Savitar is part of the namespace of my own libraries where I rolled the Panel. You don't however need the Panel as was mentioned in later posts. Remove the Savitar references and panel, and set the trigger for the CallBackPanel to the name of the ContentPlaceHolder. Works perfectly like that.
Kris Brietkopf
Posted: Tuesday, June 17, 2008 5:33:29 AM
Rank: Member
Groups: Member

Joined: 3/24/2008
Posts: 12
eo_support wrote:
Hi,

You can put a Label inside the CallbackPanel and then set the Label's Text to something like this:

Label1.Text = "<script type='text/javascript'>window.alert('hi!');</script>";

The key is your JavaScript code has to be rendered inside the CallbackPanel. The usually way of RegisterClientScriptBlock won't work.

Thanks


I used this method to handle a popup. That part works great now. The new problem is that I can no longer set focus to a specific textbox after the window.alert has been clicked. How can I have a popup from inside a callback panel and still set focus to the control that I need to draw attention to after the popup is dismissed?
eo_support
Posted: Tuesday, June 17, 2008 9:12:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Hi,

Try to call window.setTimeout to delay the execution of code that setting focus. For example, instead of using:

Code: JavaScript
e.focus();


Try:

Code: JavaScript
window.setTimeout('set_focus()', 10);

function set_focus()
{
   e.focus();
}


Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.