How can I refresh a page?

G

Guest

I have an index.aspx with frames. The top frame has a navigation bar with a "Login" hyperlink. If the user has already logged in I want this link to change to "Logout". I am using forms-based authentication and think I know how to accomplish this part. My problem is that the top frame does not reload to get to the "If User.Identity.IsAuthenticated Then". Please don't tell me I shouldn't be using frames; this is a school assignment and the deadline is a week away (no time to redo what I have already done). Is there a way to get this link to change after the top.aspx page has already loaded?

Thank you for you help,
Judy
 
G

Guest

Assuming that you are authorizing the user in a frame other than the top, but with the same parent. If this is the case you can reload the top frame with the following javascript code.

RegisterStartupScript("Reload", "<SCRIPT Language='Javascript'>parent.FRAMENAME.document.Form1.submit()</" & "Script>")

Replace the FRAMENAME with the name of the top frame as it is in the Framesetting document. You can then put the code which checks if the user has already logged on in the page_load event of top.aspx as this is the only method that will be executed when the page reloads.

If you are authorizing the user in a pop up, say from the Login link in the top frame, the javascript code will be a little different.

RegisterStartupScript("Reload", "<SCRIPT Language='Javascript'>window.opener.document.Form1.submit()</" & "Script>")

window.opener will reference the window that has opened the pop-up page. Put the code in the page_load as just described and you should not have a problem.

hope this solves your problem,
John
 
K

Ken Cox [Microsoft MVP]

G

Guest

A standard html hyperlink will not cause the page to post back to the server. Instead of using a html hyperlink, use a LinkButton asp.net web control and set its autopostback to true. This way when the user clicks the Linkbutton it will look like a hyperlink but will act like a submit button. Put your conditional code in the Page_Load. More info is needed if this does not solve you issue.

You may also want to turn off any page caching so your login could dispaly logout immediately without a delay. This may not be already an issue
 
G

Guest

When I look at the asp LinkButton I don't see an autopostback property (and I get the red wavy line if I type it in anyway). Is it called something else?

Also, with an asp hyperlink I have a NavigateUrl and Target property. I can't figure out how to make the link button launch my login.aspx page in "main". Can you give me an example of using the LinkButton to do this?

Thank you for your response!
Judy
 
G

Guest

I am authorizing the user from the "main" frame in my Login.aspx page. I would love to use the code you described below to refresh my "top" frame, but I can't figure out where to put it. I put it in the btnLogin_Click method in Login.aspx.vb, and nothing happened. I am not familiar with javascript, I have only been using vb with asp.net. Any more suggestions would be appreciated.

Thank you,
Judy
 
G

Guest

Hi Judy,

I believe you have the code in the correct place. If it is not working you can check if the name of the Frame (FRAMENAME) in my code, matches the name of the Frame as it is in the Name tag in the Framesetting document. Also for this code to work the main frame where you are executing the code has to be a sister of the login frame, meaning that they need to have the same parent. Ex.

<frameset>
<frame name="top" src="top.aspx">
<frame name="main" src="main.aspx">
</frameset>

It should look something like this. In this case you have to replace FRAMENAME with 'top'.

Also another thing is that the form name should be Form1, which is the default.

If this does not work, try right clicking on your main page after it is rendered and selecting view source. You should see the javascript code somewhere, if it is not there something else is wrong.

hope this helps,
John
 
E

Edward

John,

I've one question extended from this thread.

I've two frames in default.aspx
<iframe name="menu" runat="server"/>
<iframe name="main" runat="server"/>

login process is in Main frame, when use press the Button "Login", and
the authentication is ok, I want Menu frame refresh, the same time when Main
frame refresh or redirect.

How can I achieve this ?


Assuming that you are authorizing the user in a frame other than the top,
but with the same parent. If this is the case you can reload the top frame
with the following javascript code.
RegisterStartupScript("Reload", "<SCRIPT
Language='Javascript'>parent.FRAMENAME.document.Form1.submit()</" &
"Script>")
Replace the FRAMENAME with the name of the top frame as it is in the
Framesetting document. You can then put the code which checks if the user
has already logged on in the page_load event of top.aspx as this is the only
method that will be executed when the page reloads.
If you are authorizing the user in a pop up, say from the Login link in
the top frame, the javascript code will be a little different.
RegisterStartupScript("Reload", "<SCRIPT
Language='Javascript'>window.opener.document.Form1.submit() said:
window.opener will reference the window that has opened the pop-up page.
Put the code in the page_load as just described and you should not have a
problem.
hope this solves your problem,
John
with a "Login" hyperlink. If the user has already logged in I want this
link to change to "Logout". I am using forms-based authentication and think
I know how to accomplish this part. My problem is that the top frame does
not reload to get to the "If User.Identity.IsAuthenticated Then". Please
don't tell me I shouldn't be using frames; this is a school assignment and
the deadline is a week away (no time to redo what I have already done). Is
there a way to get this link to change after the top.aspx page has already
loaded?
 
G

Guest

Hi Edward,

The RegisterStartupScrict code below should work if you place it right after the login process. When the main frame is refreshed it will render the script and refresh the menu frame.

It will not work if you redirect the page though. If the page is redirected, the Register scripts will not render on the redirected page, and thus the menu frame will not refresh.

In order to achieve this with a redirect you would have to either do one of the following:

1 - Redirect using javascript using document.location.href=NEWPAGENAME (Add this to the startupscript.

or

2 - Insert the RegisterStartupScript code in the redirected page, possibily using a querystring to flag it to do so.

hope this helps you,
John
 

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