|
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.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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
|
|
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?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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.
|
|
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".
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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
|
|
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).
|
|
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?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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.
|
|
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" /> <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?
|
|
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.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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.
|
|
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 :)
|
|
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" /> <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 :)
|
|
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 :)
|
|
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
|
|
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.
|
|
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?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi, Try to call window.setTimeout to delay the execution of code that setting focus. For example, instead of using:
Try:
Code: JavaScript
window.setTimeout('set_focus()', 10);
function set_focus()
{
e.focus();
}
Thanks
|
|