• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2409
  • Last Modified:

Iframe parent page refresh data update

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
digitalZo
Asked:
digitalZo
  • 11
  • 5
1 Solution
 
neeraj523Commented:
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
 
digitalZoAuthor Commented:
can you show me how to do it?
0
 
neeraj523Commented:
can u post the code for inserting form data in db..
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
digitalZoAuthor Commented:
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
 
neeraj523Commented:
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
 
digitalZoAuthor Commented:
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
 
digitalZoAuthor Commented:
it also loses all the textbox value
0
 
neeraj523Commented:
"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
 
digitalZoAuthor Commented:
<<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
 
digitalZoAuthor Commented:
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
 
neeraj523Commented:
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
 
digitalZoAuthor Commented:
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
 
digitalZoAuthor Commented:
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
 
digitalZoAuthor Commented:
Nevermind, I'll open a new topic and give you the points here. Thanks once again,
0
 
digitalZoAuthor Commented:
Excellent solution. Thank you very much.
0
 
digitalZoAuthor Commented:
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

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 11
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now