By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Accessing form data

P: n/a
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_ |
| | |
-----------------------------------------------------

--
Thanks
-------------------
cz****@wsinc.com
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Use javascript to submit the Bottom form.

window.frames['frameName'].document.body.all['Form1'].submit();

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

P: n/a
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.)

Nov 18 '05 #3

P: n/a
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" <v-******@online.microsoft.com> wrote in message
news:od**************@cpmsftngxa07.phx.gbl...
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.)

Nov 18 '05 #4

P: n/a
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.)

Nov 18 '05 #5

P: n/a
Thank you for your help!

I think this is what I need!

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:7b**************@cpmsftngxa07.phx.gbl...
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.)

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.