Solved

Dropdown update from Iframe

Posted on 2008-06-23
12
225 Views
Last Modified: 2012-06-27
I have a dropdown and an Iframe in the main page. When the user enters the data in the iframe, the dropdown should update and automatically set it to the value entered by the user. Is there any way i can do this?
0
Comment
Question by:digitalZo
12 Comments
 
LVL 8

Expert Comment

by:MrAgile
ID: 21851079
Hi There,

Please post the code.

Sean
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21852365
The data entered in the iframe is in a form and you submit the form, right?  The simple way is to add the target attribute to the form tag (the form in the iframe) and give it _parent as the value.  E.g.

<form target="_parent"

That will cause the form to submit to the page with the dropdown.  Make sure the page will process the form and then make the dropdown.  To have the dropdown show the submitted value as selected you need to have your script add selected="selected" to the option tag for that item.  You can use an If to check for that value as you go through the other options.

If you need specifics on how to do this we will need code.  Let me know if you have a question.

bol
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21852666
Thanks b0lsc0tt for your reply. Now we are going somewhere.

This is the code used you to add the value to the dropdown from the form in the Iframe:

If Not (Page.IsStartupScriptRegistered("Test")) Then
          Dim temp As String
            temp = "<script language='Javascript'>"
            temp += " alert(""Successful;"");"
            temp += " var newElm = document.createElement('option');"
            temp += "  newElm.text ='" + txtcompany.Text
            temp += "';  newElm.value ='" + txtcompany.Text
            temp += "';  parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').options.add(newElm);"
            temp += " parent.document.getElementById('mydiv').style.display='none';"
            temp += "</script>"
            Page.RegisterStartupScript("Test", temp)
        End If

But how do i show the new data as selected?

Secondly, I'm using ASP.Net controls. the problem im facing is that while the data adds to the dropdown, it disappears on postback of another control. therefore, i have to refresh the whole page to keep it intact; but with this method i lose all the data in the form on the parent page.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 21855109
parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').selectedIndex =
(parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').options.length-1)
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21862876
Thanks for that code. It worked. But the problem is the dropdown shows the selected data but when I click on another dropdown which autopostbacks, the selected new data disappears from the dropdown.

Is there any solution for this?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21862917
Impossible to tell without knowing what the autopostback does.
Perhaps you need to send the new options to that postback too to include it in new forms from the server
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Author Comment

by:digitalZo
ID: 21862969
The autopostback fills the corresponding dropdown with related information. For example, dropdown "country" when selected will autopostback and fill the dropdown "state" in that selected country.

how do i send new options to the autopostback?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21863160
I do not understand (I do not do ASP so I apologise if it is obvious)
You have several controls - one you want to update with one code and the other is populated with other code

If the postback uses ajax I do not see why populating one select would influence the content of another.
If the postback refreshes the complete form, then you could save the new elements in a cookie and have the postback read that cookie - assuming the postback updated both selects.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863221
<<If the postback uses ajax I do not see why populating one select would influence the content of another.>>

im not using ajax.
<<
If the postback refreshes the complete form, then you could save the new elements in a cookie and have the postback read that cookie - assuming the postback updated both selects.>>>

how do i do this? and wont it become too complicated because im using this one form [iframe] to be called in 10 different pages.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21863280
then you need to read the cookie clientside in the return from the postback.

It seems to me you are making your life quite complicated
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863320
then you need to read the cookie clientside in the return from the postback.
>>>>>>>>.

any idea on how to go about doing it?
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863321
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now