digitalZo
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?
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.
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?
ASKER
can you show me how to do it?
can u post the code for inserting form data in db..
ASKER
this is how i've done it:
Protected Sub submit_btn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEv entArgs) 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.
Protected Sub submit_btn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEv
//database queries.
'submit_btn.Attributes.Add
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
ASKER
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 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.
ASKER
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 ?
are you passing some values in the iframe from parent page ??
can you post the live url if possible ?
ASKER
<<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.
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(""O PTION"");"
sp += " newElm.text ='" + txtcompany.Text
sp += "'; newElm.value ='" + txtcompany.Text
sp += "'; parent.getElementById('ddl _ri_vname' ).options. add(newElm )"
sp += "; parent.document.getElement ById('mydi v').style. display='n one';"
sp += "</" + "script>"
Page.RegisterStartupScript ("Done", sp)
Source code:
function closereload()
{
var newElm = document.createElement("OP TION");
newElm.text = document.getElementById("t xtcompany" ).value;
newElm.value = document.getElementById("t xtcompany" ).value;
parent.getElementById("ddl _ri_vname" ).options. add(newElm )
parent.document.getElement ById("mydi v").style. display="n one";
}
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.
Code-behind:
Dim sp As String
sp = "<script language='JavaScript'>"
sp += "var newElm = document.createElement(""O
sp += " newElm.text ='" + txtcompany.Text
sp += "'; newElm.value ='" + txtcompany.Text
sp += "'; parent.getElementById('ddl
sp += "; parent.document.getElement
sp += "</" + "script>"
Page.RegisterStartupScript
Source code:
function closereload()
{
var newElm = document.createElement("OP
newElm.text = document.getElementById("t
newElm.value = document.getElementById("t
parent.getElementById("ddl
parent.document.getElement
}
Dim sp As String
sp = "<script language='JavaScript'>"
sp += "closereload();"
sp += "</" + "script>"
Page.RegisterStartupScript
========
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.
ASKER
THANKS ALOT! I made a few modifications and it worked. These are the changes in the code:
If Not (Page.IsStartupScriptRegis tered("Tes t")) Then
Dim temp As String
temp = "<script language='Javascript'>"
temp += " alert(""Successful;"");"
temp += " var newElm = document.createElement('op tion');"
temp += " newElm.text ='" + txtcompany.Text
temp += "'; newElm.value ='" + txtcompany.Text
temp += "'; parent.document.getElement ById('ctl0 0_ContentP laceHolder 1_ddl_ri_v name').opt ions.add(n ewElm);"
temp += " parent.document.getElement ById('mydi v').style. display='n one';"
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?
If Not (Page.IsStartupScriptRegis
Dim temp As String
temp = "<script language='Javascript'>"
temp += " alert(""Successful;"");"
temp += " var newElm = document.createElement('op
temp += " newElm.text ='" + txtcompany.Text
temp += "'; newElm.value ='" + txtcompany.Text
temp += "'; parent.document.getElement
temp += " parent.document.getElement
temp += "</script>"
Page.RegisterStartupScript
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?
ASKER
Nevermind, I'll open a new topic and give you the points here. Thanks once again,
ASKER
Excellent solution. Thank you very much.
ASKER
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.
https://www.experts-exchange.com/questions/23482039/iframe-and-parent-page-refresh.html
if you know the solution to the problem, please do post.
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())
neeraj523