Solved

Iframe parent page refresh data update

Posted on 2008-06-11
16
2,378 Views
Last Modified: 2010-05-18
Please take a look at this link:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23474810.html

i added this in form tag and the parent page refreshes:
  <form id="form1" runat="server" onsubmit="parent.location.reload();">

the only problem it's showing is that if the form is not yet filled then the page reloads with the new data in the dropdown without any hitches....but if there's data on the parent page, then on refresh, either the data stays intact but the new data does not get inserted in the dropdown OR the data disappears.

any idea why this is happening? and solution?
0
Comment
Question by:digitalZo
  • 11
  • 5
16 Comments
 
LVL 22

Expert Comment

by:neeraj523
ID: 21758498
Hello

I will not suggest you to refersh your parent page on form submit..

Instead, you should refresh your parent page after inserting form data in into database.. You should write javascript statement (parent.location.reload()) which will be executed after data insert (if succesfull)..

neeraj523
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21758524
can you show me how to do it?
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21758589
can u post the code for inserting form data in db..
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21758601
this is how i've done it:

Protected Sub submit_btn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles submit_btn.Click
               //database queries.
 
                'submit_btn.Attributes.Add("OnClick", "javascript:closeiframe();return false;")
    End Sub

^altho if i add that attribute and remove the function from the form, i've to click twice on the button to submit [which does not refresh the page either]. so i've temporarily commented it.
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21758684
here you go


Protected Sub submit_btn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles submit_btn.Click

               //database queries.

        Dim sp As String

        sp = "<script language='JavaScript'>"

        sp += "parent.location.reload();"

        sp += "</" + "script>"

        RegisterStartupScript("Done", sp);

                'submit_btn.Attributes.Add("OnClick", "javascript:closeiframe();return false;")

    End Sub

Open in new window

0
 
LVL 10

Author Comment

by:digitalZo
ID: 21758750
your code behaves similar to how it was behaving on form submit.

it throws up this IE error when the user has selected the data on parent page and is then entering the form which in an iframe.
>>>>>>>>
To display the webpage again, Internet Explorer needs to resend the
information you've previously submitted.

If you were making a purchase, you should click the Cancel to avoid a
duplicate transaction. Otherwise, clidck Retry to display the webpage again."
<<<<<<<<

when this error comes, the dropdown doens't update while the data in the parent form remains intact. if the dropdown [which is on the parent form] does update with the new data, then the data in parent form disappears.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21758753
it also loses all the textbox value
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21758814
"it throws up this IE error when the user has selected the data on parent page and is then entering the form which in an iframe. " what you mean bye "user entering in iframe"

are you passing some values in the iframe from parent page ??

can you post the live url if possible ?

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 10

Author Comment

by:digitalZo
ID: 21758980
<<what you mean bye "user entering in iframe">>>
There's a form in the Iframe which opens up and the user has to enter the details. When he clicks on the submit button, the data inserts into db and the form should close automatically while displaying the updated dropdown on the main page. This is what should ideally happen.

Let me try to explain the whole scenario again:

I have a main form. ON that form, there's a dropdown. if the user doesnt find the required option in the dropdown, he clicks on the 'new' button. when he clicks, a form opens in an iframe like a popup. the user enters the details and clicks on submit. then the form should close, and display the dropdown with the updated option.

now, what is happening is that *before* the dropdown there are few more dropdowns and textboxes. the user enters the fields and selects the required option. now he comes to the dropdown - he doesnt find the required option in the dropdown, so clicks on the button. the form opens, he enters the data and clicks submit. here, your code helps, because the form closes and the page reloads. now when the page reloads, all the data which was entered before by the user on the main form is lost and the dropdown doesn't update either.

i hope you get the problem now.

<<<<are you passing some values in the iframe from parent page ??>>>>>
No

<<<<<can you post the live url if possible ?>>>>>
Unfortunately it's not live.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21758993
i would like to add that when the user doesnt enter any details in the main form but  directly clicks on the button and enters the details into the form, then it works fine. the dropdown is updated and since there is no data to disappear, nothign ofcoz disappears.
0
 
LVL 22

Accepted Solution

by:
neeraj523 earned 500 total points
ID: 21759312
Hmm.. got it..

you should not refresh the paranet page.. instead use javascript in iframe page to add newely added drop down item in the parnent page after form submit..

somthing like this

I havnt tested this script.. so any syntex error need to be handled as needed..
Dim sp As String

        sp = "<script language='JavaScript'>"

	sp = "var newElm = document.createElement(""OPTION"")"

	sp = "newElm.text =" + itemText

	sp = "newElm.value =" + itemVal 

	parent.getElementById("[parentDropDown]").options.add(newElm)

        sp += "</" + "script>"

        RegisterStartupScript("Done", sp);
 

where itemText and itemVal is the data what you entered in database and need to be added to the drop down in parent page.. [parentDropDown] is the id of dropdown in parent page

Open in new window

0
 
LVL 10

Author Comment

by:digitalZo
ID: 21776165
I tried your solution with a few changes, both in the source code as well as code-behind:

Code-behind:
Dim sp As String
sp = "<script language='JavaScript'>"
sp += "var newElm = document.createElement(""OPTION"");"
sp += "  newElm.text ='" + txtcompany.Text
sp += "';  newElm.value ='" + txtcompany.Text
sp += "';  parent.getElementById('ddl_ri_vname').options.add(newElm)"
sp += ";  parent.document.getElementById('mydiv').style.display='none';"
sp += "</" + "script>"
Page.RegisterStartupScript("Done", sp)

Source code:
function closereload()
    {
        var newElm = document.createElement("OPTION");
        newElm.text = document.getElementById("txtcompany").value;
        newElm.value = document.getElementById("txtcompany").value;
        parent.getElementById("ddl_ri_vname").options.add(newElm)
        parent.document.getElementById("mydiv").style.display="none";
    }
       

 Dim sp As String
sp = "<script language='JavaScript'>"
sp += "closereload();"
 sp += "</" + "script>"
Page.RegisterStartupScript("Done", sp)

========

it gives this javascript error:

"object doesnt support this propery or method"

and also the child popup doesnt close; neither is it refreshing the dropdown.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21776710
THANKS ALOT! I made a few modifications and it worked. These are the changes in the code:

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


Now the only problem is that the data shows in the dropdown. I go to the next dropdown whose AutoPostBack is set to True. I choose an option from the dropdown. It postbacks to the server and the newly added data to the previous dropdown disappears although the value is in the database. How do I solve this? And why is this happening, when on postback it should be actually showing the new data?
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21776714
Nevermind, I'll open a new topic and give you the points here. Thanks once again,
0
 
LVL 10

Author Closing Comment

by:digitalZo
ID: 31466075
Excellent solution. Thank you very much.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21776880
i've opened a new topic here:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23482039.html

if you know the solution to the problem, please do post.
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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

747 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

10 Experts available now in Live!

Get 1:1 Help Now