HI All.
Today I m going to describe the use of the window.opner function .Basically It is used to update the Value Of parent page from the child pop Up page.
The fully described code is given as below.
Step 1.) Parent Page.
A.) Script of the parent page :
function goChild()
{
window.open("~\WindowOpener\ChildPage.aspx");
}
B.)HTML of this page is :
[form id="form1" runat="server"]
[div]
[asp:Label ID="lblSum" runat="server" /][br /]
[br /]
[asp:Button ID="btnChild" OnClientClick="goChild();" Text="PopUp Open" runat="server" / /]
[br /]
[/div]
[/form]
C.) The Code Behind File of the Page.
There is no need to write any line of the code for this little Example
Step 2.)child Popup page.
A.) Script of the Child popUp page
function SumAndGO(varValue)
{
self.close();
window.opener.document.getElementById('lblSum').innerHTML=varValue;
}
function Validation(varValue)
{
for(i=0; i< varValue.length ;i++)
{
alert(varValue.charCodeAt(i));
}
}
B.) HTML of this page is :
[body]
[form id="form1" runat="server"]
[div]
Number 1: [asp:TextBox onblur="Validation(this.value);" ID="TxtNum1" runat="server"][/asp:TextBox][br /]
Number 1: [asp:TextBox ID="TxtNum2" runat="server"][/asp:TextBox][br /]
[asp:Button ID="btnSum" runat="server" Text="Go For Sum" OnClick="btnSum_Click" /]
[/div]
[/form]
[/body]
c.) The Code Behind File of the Page.
protected void btnSum_Click(object sender, EventArgs e)
{
int sum = Convert.ToInt32(TxtNum1.Text) + Convert.ToInt32(TxtNum2.Text);
string Jscript = "SumAndGO(" + sum + ")";
Jscript = "";
ClientScript.RegisterStartupScript(typeof(Page), "Jscript", Jscript);
}
Regards:
Sanjeev Chauhan
Thursday, November 27, 2008
Tuesday, November 25, 2008
How To Register Client Script Inside Update Panel.
Hi EveryBody...
To use client script inside an update panel at runtime, you have to use "ScriptManager.RegisterClientScriptBlock". Just check if the input parameters are right, say for example you have:
ScriptManager.RegisterClientScriptBlock(UpdatePanelName, UpdatePanelName.GetType(), "jscript", "JavaScript Function", true);
Here parameter 1: the name of your update panel (Control Name).
parameter 2: you are passing the type of control, you have GetType() function which returns the type of control
parameter 3: telling it is "jscript" you want to execute
parameter 4: the name of the JavaScript function you want to call
parameter 5: true to enclose the script block in tags; otherwise, false.
For example we can use it as given below:-
string JScript = string.Empty;
JScript = "alert('Jai Sri RamChandra ji maharaaj')";
JScript = "[script language='javascript']" + JScript + "[/script]";
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, UpdatePanel1.GetType(), "JScript", JScript,false);
Hope this improves your coding.
Sanjeev Chauhan
To use client script inside an update panel at runtime, you have to use "ScriptManager.RegisterClientScriptBlock". Just check if the input parameters are right, say for example you have:
ScriptManager.RegisterClientScriptBlock(UpdatePanelName, UpdatePanelName.GetType(), "jscript", "JavaScript Function", true);
Here parameter 1: the name of your update panel (Control Name).
parameter 2: you are passing the type of control, you have GetType() function which returns the type of control
parameter 3: telling it is "jscript" you want to execute
parameter 4: the name of the JavaScript function you want to call
parameter 5: true to enclose the script block in tags; otherwise, false.
For example we can use it as given below:-
string JScript = string.Empty;
JScript = "alert('Jai Sri RamChandra ji maharaaj')";
JScript = "[script language='javascript']" + JScript + "[/script]";
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, UpdatePanel1.GetType(), "JScript", JScript,false);
Hope this improves your coding.
Sanjeev Chauhan
Subscribe to:
Posts (Atom)