?
Solved

How to access server control from another page?

Posted on 2008-10-12
12
Medium Priority
?
1,325 Views
Last Modified: 2008-10-20
Hi, I have two pages main.aspx and list.aspx, the main.aspx page contains an iframe which is loaded by list.aspx page, now I want to access a server control in main.aspx page from list.aspx page, how can I do that?
0
Comment
Question by:Abdu_Allah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22697586
You can access the data of one page in another page only when the first page is redirecting or transfering code execution to the second page.
Hope the below links will help you
http://msdn.microsoft.com/en-us/magazine/cc163722.aspx

You can get more samples on net if you search on how to use "PreviousPage" property in asp.net




0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22697635
There is no redirecting or transferreing in my case. The list.aspx page will do some serverside operations and within these operation I must access the control in main.aspx page.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22697890
Does that mean that you are not redirecting or submitting main.aspx page to list.aspx page?

If that is the case then you wont be able to access controls that are in main.aspx from list.aspx page.

When ever you request for a page, whether it is on postback or not, asp.net will be creating a new instance of the page and add the data in viewstate to the corresponding controls. The instance of other pages wont be available. That is how ASP.NET works, not like windows applications. But you can access data from one page in another through session variables, or by storing in a database or cookies

For more info on passing data from one page to another
http://forums.asp.net/t/1315570.aspx

Hope that clarifies
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22698060
The instances of main.aspx and list.aspx are both alive, because list.aspx is within iframe in main.aspx.
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22698101
Sure you can get the Value of a parent window that contains a iframe, but it all depends what you want to do with the Value.

For Example, Server Side using pure Asp.net you are able to do this. but by using client side javaScript, you can get the Value of Parent Windows's Server Control Such as (Textbox, Div span) Values.

So as long as you know the ClientID of a control you can access its values. But please keep in mind you can not mix javaScript Code with Aspx Code.


IFrame Code:
 
<input type="button" onClick="alert(parent.document.getElementById('getme').value)" value="Get 
 
main Windows's Textbox">
 
 
Parent Window Code:
 
<input type="text" id="getme">
 
<iframe src="hello.html">
Parent Windows's Textbox Content">
</iframe>

Open in new window

0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22698104
Ok I was thinking the other way.
Then you can access the controls using javascript
var control = window.frames[<framename>].document.getElementById('<controlname>')

then get the value from control and do what ever you want.
But the same thing cannot be done from server side code.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22698110
If you want to pass this value to server code assign the value to a hidden variable and access from server side code
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22698143
I said accessing serverside control from serverside operation, no javascript.
0
 
LVL 23

Accepted Solution

by:
Saqib Khan earned 2000 total points
ID: 22698169
Then you are out of luck.
Try the hidden field technique as suggested above. or Submit the form of main page into "Iframe" using javaScript and get your control's values.
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 22698186
how do you access a hidden feild from serverside function!
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22698212
Lets Talk About Iframe Code.

User Clicks on a Button within Iframe Page to get the Value of a control in Main Page.
in I Frame you must have a Hidden Field.
<input type="hidden" runat="server" id="someId_Hidden" />

now when you click button in Iframe, update the Value of hidden field with the Value of the Server Side control  of main window(using javaScript).

document.getElementById('someId_Hidden').value = parent.document.getElementById('getme').value

where "getme" is a serverSide Control ID in main page.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22698227
You can access a hidden field in server side control the same way you access other controls suppose your hidden field is named HiddenField1
<asp:HiddenField ID="HiddenField1" runat="server" />

In server side you can access it as HiddenField1.value to get its value
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question