2010/10/22

Aspx page, Frameset, and QueryString

I encountered a situation that I have to pass values through the query string to an aspx page which contains frameset settings. Here is what I found how to do it (and it works for me).

Let's say I have a Default.aspx which has a frameset settings, and it contains two frames link to Menu.aspx and Content.aspx. Here is the html code for the Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
  <title>xxxx</title>
 </head>
 <frameset cols="20%,80%">
  <frame name="Menu" src=<%= GetMenuFrame()%> />
  <frame name="Content" src=<%= GetContentFrame()%> />
 </frameset>
</html>

Here the GetMenuFrame() and GetContentFrame() are the methods you need to implement in your code-behind file.
protected void Page_Load(object sender, EventArgs e)
{
}

protected string GetMenuFrame()
{
    return "Menu.aspx?uid=" + Request.QueryString["uid"];
}

protected string GetContentFrame()
{
    return "Content.aspx?mid=" + Request.QueryString["mid"];
}
PS: These methods cannot be "private". You can make it "public" if you want.

How to use:
http://xxx/Default.aspx?uid=123&mid=456
Now you can pass/retrieve values through the query string.

Please let me know if you have other thoughts.

No comments:

Post a Comment