asp.net practical tips (2)

Source: Internet
Author: User
Asp.net| Tips

1. In the ASP.net practical tip (1), you mentioned how to refresh the parent page, so if you want to refresh the parent page of the parent page? That is refreshing the ancestor page refreshancestorpage.

Refreshancestorpage#region Refreshancestorpage
/**////<summary>
Refreshes the specified ancestor page, noting that the ancestor page
</summary>
public static void Refreshancestorpage (HttpResponse Response, string targetpagetitle, bool isclosecurpage)// Title of Targetpagetitle target page
{
StringBuilder scriptstring = new StringBuilder ();
Scriptstring.append ("<script language = javascript>");
Scriptstring.append ("var p = window;");
Scriptstring.append (String. Format ("While" (P.document.title!= ' {0} '), Targetpagetitle));
Scriptstring.append ("{");
Scriptstring.append ("p = p.opener;");
Scriptstring.append ("}");
Scriptstring.append ("P.focus ();");
Scriptstring.append ("P.refresh ();");

if (isclosecurpage)
{
Scriptstring.append ("Window.focus ();");
Scriptstring.append ("window.opener=null;");
Scriptstring.append ("Window.close ();");
}

Scriptstring.append ("</" + "script>");

Response.Write (Scriptstring.tostring ());
}

/**//*
You need to add the following script (in header) to the HTML of the Father page:
<script language= "JavaScript" >
function Refresh ()
{
This.location = this.location;
}
</script>
*/
#endregion

2. How do I refresh the page in one of the frame in the ancestor page?

Refreshframeinancestorpage#region Refreshframeinancestorpage
/**////<summary>
Refreshes the internal page of a frame in a specified ancestor page
</summary>
public static void Refreshframeinancestorpage (HttpResponse Response, String ancestortitle, String framename, String TargetUrl, bool Isclosecurpage)//targetpagetitle title of the target page
{
StringBuilder scriptstring = new StringBuilder ();
Scriptstring.append ("<script language = javascript>");
Scriptstring.append ("var p = window;");
Scriptstring.append (String. Format ("While" (P.document.title!= ' {0} '), Ancestortitle));
Scriptstring.append ("{");
Scriptstring.append ("p = p.opener;");
Scriptstring.append ("}");
Scriptstring.append ("P.focus ();");
Scriptstring.append (String. Format ("p.{0}.location = ' {1} ';", FrameName, TargetUrl));

if (isclosecurpage)
{
Scriptstring.append ("Window.focus ();");
Scriptstring.append ("window.opener=null;");
Scriptstring.append ("Window.close ();");
}

Scriptstring.append ("</" + "script>");

Response.Write (Scriptstring.tostring ());
}
#endregion

3. How do I refresh the other frames on this page?

Refreshtargetframeinsamepage#region Refreshtargetframeinsamepage
/**////<summary>
Refresh any frame in the same page from a frame (including your own frame)
</summary>
public static void Refreshtargetframeinsamepage (HttpResponse Response, String framename, String targeturl)
{
String scripstr = String. Format ("<script language = ' JavaScript ' > window.parent.{ 0}.location= ' ", framename) +targeturl +" ' ";
Scripstr + + "</" + "script>";
Response.Write (SCRIPSTR);
}
#endregion

4. How do I invoke a script from an ancestor page?

Callancestorscriptmethod#region Callancestorscriptmethod
/**////<summary>
Invokes the script for page inside a frame within the ancestor page, if it is a script that invokes an ancestor page, Targetframename passes in null
</summary>
public static void Callancestorscriptmethod (HttpResponse Response, String targetpagetitle, String targetframename, String methodname, string[] parastrs)
{
StringBuilder scriptstring = new StringBuilder ();
Scriptstring.append ("<script language = javascript>");
Scriptstring.append ("var p = window;");
Scriptstring.append (String. Format ("While" (P.document.title!= ' {0} '), Targetpagetitle));
Scriptstring.append ("{");
Scriptstring.append ("p = p.opener;");
Scriptstring.append ("}");
if (targetframename!= null)
{
if (parastrs = null)
{
Scriptstring.append (String. Format ("p.frames[' {0} '].{ 1} (); ", Targetframename, MethodName);
}
Else
{
String rparastr = String. Format ("' {0} ', parastrs[0]);"
for (int i=1; i<parastrs.length; i++)
{
Rparastr = = String. Format (", ' {0} '", Parastrs[i]);
}
Scriptstring.append (String. Format ("p.frames[' {0} '].{ 1} ({2}); ", Targetframename, MethodName, RPARASTR);
}
}
Else
{
if (parastrs = null)
{
Scriptstring.append (String. Format ("p.{0} ();", MethodName));
}
Else
{
String rparastr = String. Format ("' {0} ', parastrs[0]);"
for (int i=1; i<parastrs.length; i++)
{
Rparastr = = String. Format (", ' {0} '", Parastrs[i]);
}
Scriptstring.append (String. Format ("p.{0}" ({1}); ", MethodName, Rparastr));
}

}

Scriptstring.append ("</" + "script>");
Response.Write (Scriptstring.tostring ());
}
#endregion

5. How do I invoke the script for the other frames page in this screen?

Calltargetframescriptmethodinsamepage#region Calltargetframescriptmethodinsamepage
/**////<summary>
Invokes the script for page inside other frames in this page,
</summary>
public static void Calltargetframescriptmethodinsamepage (HttpResponse Response, String targetframename, String MethodName, string[] parastrs)
{
StringBuilder scriptstring = new StringBuilder ();
Scriptstring.append ("<script language = javascript>");

if (parastrs = null)
{
Scriptstring.append (String. Format ("window.parent.{ 0}. {1} ();; ", Targetframename, MethodName));
}
Else
{
String rparastr = String. Format ("' {0} ', parastrs[0]);"
for (int i=1; i<parastrs.length; i++)
{
Rparastr = = String. Format (", ' {0} '", Parastrs[i]);
}
Scriptstring.append (String. Format ("window.parent.{ 0}. {1} ({2});; ", Targetframename, MethodName, Rparastr));
}

Scriptstring.append ("</" + "script>");
Response.Write (Scriptstring.tostring ());
}
#endregion

Visible above these functions are done through the script, if not familiar with the script, it is impossible to do web development!




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.