Situation:
I have had a scenario while developing one application like need to open a child window for adding attachments for the parent window. There is a link in parent window along with No. of attachments has to be displayed near by the link. The thing is the parent form control should be updated when user adds/deletes attachment in child form.
Solution:
I believe most of the people known about the "window.opener" is pointing the parent form and can manage this with some Javascript code. Here one more thing also there. When you write Javascript code, this has to be called during add/delete button click of server side event. This can be achieved by "RegisterClientScriptBlock" of ClientScript object.
Code Sample :
StringBuilder RTScript = new StringBuilder();
RTScript.Append("script>window.opener.document.forms['aspnetForm']." +
"ControlName.value = '[" + AssigningValue + "]';script");
ClientScript.RegisterClientScriptBlock(this.GetType(), "script", RTScript.ToString());
Kindly add less than[<] symbol before and after the script tag in the above code.
In the above code you have to change it in two places one is ControlName, which is the name of the control in parent window and AssigningValue, whats the value you want to display it in the parent window.
Happy .Neting.. :)
I have had a scenario while developing one application like need to open a child window for adding attachments for the parent window. There is a link in parent window along with No. of attachments has to be displayed near by the link. The thing is the parent form control should be updated when user adds/deletes attachment in child form.
Solution:
I believe most of the people known about the "window.opener" is pointing the parent form and can manage this with some Javascript code. Here one more thing also there. When you write Javascript code, this has to be called during add/delete button click of server side event. This can be achieved by "RegisterClientScriptBlock" of ClientScript object.
Code Sample :
StringBuilder RTScript = new StringBuilder();
RTScript.Append("script>window.opener.document.forms['aspnetForm']." +
"ControlName.value = '[" + AssigningValue + "]';script");
ClientScript.RegisterClientScriptBlock(this.GetType(), "script", RTScript.ToString());
Kindly add less than[<] symbol before and after the script tag in the above code.
In the above code you have to change it in two places one is ControlName, which is the name of the control in parent window and AssigningValue, whats the value you want to display it in the parent window.
Happy .Neting.. :)
No comments:
Post a Comment