Link to home
Start Free TrialLog in
Avatar of digitalZo
digitalZoFlag for India

asked on

Iframe parent page refresh data update

Please take a look at this link:

https://www.experts-exchange.com/questions/23474810/Iframe-close-on-submit-data-and-refresh-parent.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?
Avatar of neeraj523
neeraj523
Flag of India image

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
Avatar of digitalZo

ASKER

can you show me how to do it?
can u post the code for inserting form data in db..
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.
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

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.
it also loses all the textbox value
"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 ?

<<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.
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.
ASKER CERTIFIED SOLUTION
Avatar of neeraj523
neeraj523
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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?
Nevermind, I'll open a new topic and give you the points here. Thanks once again,
Excellent solution. Thank you very much.
i've opened a new topic here:
https://www.experts-exchange.com/questions/23482039/iframe-and-parent-page-refresh.html

if you know the solution to the problem, please do post.