Run client script after postback
-
Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC
-
Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC
Hi RC. So the post to the server is happening in frame #1, and you'd like to then have the response in frame #1 signal a redirect in frame #2?
-
Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC
I don't know if this would be a proper solution, but you could use
if(Page.IsPostBack)
Page.RegisterStartupScript("my_redirect_script", TheScriptItSelf);Rado
Radoslav Bielik http://www.neomyz.com/poll [^] - Get your own web poll
-
Hi RC. So the post to the server is happening in frame #1, and you'd like to then have the response in frame #1 signal a redirect in frame #2?
Yep, that's what I would like to do.
-
Yep, that's what I would like to do.
Hi there. Try this out - copy each of these blocks to four seperate files with the given names, then load frames.htm in your browser. I'm using a
Literal
control in frames1.aspx to output the necessary javascript to redirect the second frame. File 1 - frames.htm<html>
<head>
<frameset cols="*, 50%">
<frame name="frame1" src="frame1.aspx">
<frame name="frame2" src="frame2a.aspx">
</frameset>
</head>
</html>File 2 - frame1.aspx
<%@Page Language="C#" %>
<script runat="server">
void HandleSubmit(Object o, EventArgs e)
{
Session["Var1"] = txtVar1.Text;
Session["Var2"] = txtVar2.Text;string sRedirect = "parent.frame2.location.href = 'frame2b.aspx';"; literalRedirect.Text = sRedirect; }
</script>
<html>
<head>
<script language="javascript">
<asp:Literal runat="server" id="literalRedirect" />
</script>
</head>
<body>
<form runat="server">
<h3>This is Frame 1</h3>
Enter what you want for session variables
<table>
<tr><td>Var1</td>
<td><asp:TextBox runat="server" id="txtVar1"/></td>
</tr>
<tr><td>Var2</td>
<td><asp:TextBox runat="server" id="txtVar2"/></td>
</tr>
</table>
<asp:Button runat="server" id="btnSubmit"
text="Submit" onClick="HandleSubmit" />
</form>
</body>
</html>File 3 - frame2a.aspx
<html>
<head></head>
<body>
<form runat="server">
<h3>This is Frame 2</h3>
BEFORE the redirection
</form>
</body>
</html>File 4 - frame2b.aspx
<%@ Page language="C#" %>
<script runat="server">
void Page_Load(Object o, EventArgs e)
{
literal1.Text = Session["Var1"].ToString();
literal2.Text = Session["Var2"].ToString();
}
</script><html>
<head></head>
<body>
<form runat="server">