Easy Frames Question

V

Verde

I have a "page" comprised of 3 frames - top, bottom left, and bottom right
(A, B, and C).

From C (bottom right), I have a button (within a <form>), that when clicked
causes a bunch of stuff to happen in a database during postback - no
problem. What I want is for the last part of that postback logic (in the
button_Click event procedure) to somehow cause the page in frame B to
reload/refresh. That is (to oversimplify) - click a button in C and have B
reload/refresh.

How can this be done? I tried Server.Transfer and Response.Redirect - but
those both cause the page for B to show up in C... not what I want.

Thanks!
 
S

Steve C. Orr [MVP, MCSD]

You need to execute some client side code to do this.
Here's some javascript code that might do the trick for you:
parent.FRAMENAME.location.reload(true);

Here's more info:
http://msdn.microsoft.com/library/d...thor/dhtml/reference/objects/obj_location.asp

You could also use the RegisterClientScriptBlock or RegisterStartupScript
functions to help you with this.
Here's more info on these:
http://msdn.microsoft.com/library/d...UIPageClassRegisterClientScriptBlockTopic.asp
http://msdn.microsoft.com/library/d...UIPageClassRegisterClientScriptBlockTopic.asp
 
V

Verde

Thanks for the JavaScript snippet. Now I only need to know how to get that
JavaScript to execute after the post-back logic has executed. That is, when
the user clicks the button, I need for the PostBack to occur (and execute
all the server-side logic), followed by the JavaScript function call on the
client. Is that possible?
 
S

Stanley

Look into RegisterStartupScript.

-Stanley

Verde said:
Thanks for the JavaScript snippet. Now I only need to know how to get that
JavaScript to execute after the post-back logic has executed. That is, when
the user clicks the button, I need for the PostBack to occur (and execute
all the server-side logic), followed by the JavaScript function call on the
client. Is that possible?





http://msdn.microsoft.com/library/d...thor/dhtml/reference/objects/obj_location.asp
http://msdn.microsoft.com/library/d...UIPageClassRegisterClientScriptBlockTopic.asp have
 
V

Verde

Thanks. I read that topic and all other topics recommended in this thread.
However, I'm not concerned with programmatically sending script to the
browser. What I need to know is how to execute the client-side script after
any server-side processing has happened - like this.

1. the user sees the page (which has 3 frames).
2. the user clicks a button in a page rendered in frame C.
3. as a result of clicking the button, a PostBack occurs and server-side
code executes.
4. after the server-side code executes, the client-side JavaScript is
executed (which refreshes the page in frame B). The JavaScript earlier in
this thread posted by Steve Orr does the trick for this particular step.

I need 3 and 4 in the list above to both happen, and in the order presented,
as a result of 2 (the user clicks a button).

That is, one button click results in a postback followed by client-side
script executing.

Is this possible? If so how.

Thanks.
 
S

Stanley

Yes that is why you should use RegisterStartupScript. At the end of your
server side execution your last step would be to register that script and it
will run.

-Stanley
 
V

Verde

Some success, but still no dice - I hope I'm missing something obvious: I
had success using RegisterStartupScript to get the script rendered to the
browser. It just isn't getting executed automatically.

Here's my code-behind test function:
private void btnReloadMenu_Click(object sender, System.EventArgs e) {
String scriptString = "<script language=JavaScript> function ReloadMenu()
{";
scriptString += "parent.leftFrame.location.reload(true);}<";
scriptString += "/";
scriptString += "script>";

if(!this.IsClientScriptBlockRegistered("clientScript")){
this.RegisterStartupScript("clientScript", scriptString);
//this.RegisterClientScriptBlock("clientScript", scriptString);
}
}

Here's the HTML definition of btnReloadMenu - which calls the test function
above:
<asp:Button id="btnReloadMenu" EnableViewState="false" visible="true"
CommandName="ReloadMenu" Width="110" runat="server" Text="Reload
Menu"></asp:Button>

I separately have a link (for testing purposes only) that will explicitly
call the JavaScript function:
<A HREF="#" onClick="javascript:ReloadMenu()">Refresh Menu</A>).

When the page first loads, the JavaScript is not part of the page (as viewed
in the source via the browser), and clicking the test link (above) results
in an error saying that the function could not be found (as expected).

When the page first loads, and then the user clicks on btnReloadMenu, then
the test link will subsequently work (as the script is now part of the page
per RegisterStartupScript).

What I was expecting and needing is for the script to get executed when
btnReloadMenu gets clicked.

What am I missing?

Thanks for hanging in there on this one with me.
 
V

Verde

My apologies if I'm just being dumb - but I really don't understand the
recommendation.
If I take the javascript out of the function, then where does it go? If this
is really simple, could you provide a sample?

I hate to keep a thread going if I should be able to RTFM - but I have read
it and you're the only person who seems to know how to get what I'm after.

Thanks again.
 
S

Stanley

put the code below in place of what you have now.

private void btnReloadMenu_Click(object sender, System.EventArgs e) {
String scriptString = "<script
language=JavaScript>parent.leftFrame.location.reload(true)</script>";

if(!this.IsClientScriptBlockRegistered("clientScript")){
this.RegisterStartupScript("clientScript", scriptString);
//this.RegisterClientScriptBlock("clientScript", scriptString);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top