Accessing form data

P

Peter

I have 3 ASP.NET forms written in C#, I also have 3 frames (left, top and bottom) one for each form. My question is if I have data on one form in the bottom frame how do I access this data when I click on the button which is on the top frame?

I want to save the data from the bottom frame to the database when a user clicks on the Update button.

Does anyone have an example on how to do this?

-----------------------------------------------------
| | Top |
| | |Update| |
| |---------------------------------------|
| | Bottom |
| Left | |
| | _Data_ _Data_ _Data_ _Data_ |
| | |
| | _Data_ _Data_ _Data_ |
| | |
 
M

MSFT

Hi Peter,


Welcome to Microsoft Newsgroup Service. Based on your problem description,
you've a frameset which has three frames(left,right top and right bottom).
There is a button in the right top frame's page and some entry fields in
the right bottom page, you want to let the datas to be saved( submit to the
serverside?) when the button in the right bottom frame is clicked?

If so , I think suggestion provided by Natty is good. You can write a
period of client javascript and when the button in the right top frame is
clicked, run the script and find the right bottom frame , then call the
form(in the right bottom frame's page) 's submit() method to post the data
to the serverside, For example:

suppose we 've a frameset page as:

<frameset id="fsleft" cols="20%,80%">
<frame name="left" src="SideMenu.aspx" scrolling="no" noresize
style="BACKGROUND-COLOR: #ffffcc">
<frameset id="fsright" rows="16%,84%">
<frame name="rtop" src="TopMenu.aspx">
<frame name="rbottom" src="MainScreen.aspx">
</frameset>
</frameset>


and in the TopMenu.aspx, there exists a button and we define a javascript
function to call the rbottom frame's page's submit() method:
.........
<script language="javascript">
function SubmitBottomPage()
{
window.parent.frames['rbottom'].document.Form1.submit();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><INPUT type="button" value="SubmitButtomPage"
onclick="SubmitBottomPage()"></td>
</tr>
</table>
</form>
</body>

Thus, when the button "SubmitButtomPage" is clicked, it'll call the
"SubmitBottomPage()" function and in that function,
we use window.parent.frames['rbottom'] to get the right bottom frame's page
and call it's document.Form1 element's submit method.

The MainScreen.aspx(the page in the "rbottom" frame) is like bellow:
...................
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></FONT></td>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></FONT></td>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox></FONT></td>
</tr>
</table>
</form>
</body>

When the page is submited, all the data is posted to the serverside, you
can retrieve them in the page's Page_Load event.

Please try the preceding suggestion and let me know whether they help,
Thanks.



Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Peter

Thanks for your help!

This works!

One more question!
The Page_Load event fires when the page gets loaded initialy and once again
when you submit the form, is there a special flag that I can test to see if
data has been entered / changed on the form by the user or do I have to set
my own flag?

MSFT said:
Hi Peter,


Welcome to Microsoft Newsgroup Service. Based on your problem description,
you've a frameset which has three frames(left,right top and right bottom).
There is a button in the right top frame's page and some entry fields in
the right bottom page, you want to let the datas to be saved( submit to the
serverside?) when the button in the right bottom frame is clicked?

If so , I think suggestion provided by Natty is good. You can write a
period of client javascript and when the button in the right top frame is
clicked, run the script and find the right bottom frame , then call the
form(in the right bottom frame's page) 's submit() method to post the data
to the serverside, For example:

suppose we 've a frameset page as:

<frameset id="fsleft" cols="20%,80%">
<frame name="left" src="SideMenu.aspx" scrolling="no" noresize
style="BACKGROUND-COLOR: #ffffcc">
<frameset id="fsright" rows="16%,84%">
<frame name="rtop" src="TopMenu.aspx">
<frame name="rbottom" src="MainScreen.aspx">
</frameset>
</frameset>


and in the TopMenu.aspx, there exists a button and we define a javascript
function to call the rbottom frame's page's submit() method:
........
<script language="javascript">
function SubmitBottomPage()
{
window.parent.frames['rbottom'].document.Form1.submit();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><INPUT type="button" value="SubmitButtomPage"
onclick="SubmitBottomPage()"></td>
</tr>
</table>
</form>
</body>

Thus, when the button "SubmitButtomPage" is clicked, it'll call the
"SubmitBottomPage()" function and in that function,
we use window.parent.frames['rbottom'] to get the right bottom frame's page
and call it's document.Form1 element's submit method.

The MainScreen.aspx(the page in the "rbottom" frame) is like bellow:
..................
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></FONT></td>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></FONT></td>
<td><FONT face="ËÎÌå">
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox></FONT></td>
</tr>
</table>
</form>
</body>

When the page is submited, all the data is posted to the serverside, you
can retrieve them in the page's Page_Load event.

Please try the preceding suggestion and let me know whether they help,
Thanks.



Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Peter,


Thanks for your response. As for your question in the reply, I think you
need to add a custom flag yourself in the page which is to be submited.
Because you submit the whole page, the serverside won't know whether one of
the entry field has been modified or not. To manually add a flag, I think
you can add a hidden input area in the page(set as runat server) to perform
the flag, just like:

//default value is "no" indicate that no entry fields has been modified
<input type="hidden" name="ModifyFlag" id="ModifyFlag" runat="server"
value="no" />

and in the page , add a javascript function to modified the hidden input
area:
<script language=javascript>
function SetModifyFlag()
{
document.Form1.ModifyFlag.value = "yes"
}
</script>


Then, in other entryfield's client attributes, add a "onchange" event set
as the "SetModifyFlag" function, for example:

<input type="text" id="txtName" name="txtName" runat="server"
onchange="SetModifyFlag()">
Since this is a client script, when the textbox's value is changed ,the
"ModifyFlag" hidden area's value'll be set as "yes"
#note that you'd better use <input type="text" runat="server"/> rather than
the <asp:textbox> because the html serveside control is easier to set its
client attributes than the ASP.NET webcontrol.

Thus in the serveside code, you can check the value to know whether any
entryfield has been modified:

private void Page_Load(object sender, System.EventArgs e)
{
if(ModifyFlag.Value.Equals("yes")
{
//do operations..........
}

}


Please try the preceding suggestion and let me know whether they help,
Thanks.

Merry Christmas!!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top