Master Board page. Master

Source: Internet
Author: User

New-site

Master page: Add New Item-master page. End of Master
When used, set master page-Add new item-Lower right corner Select Master Page
Can replicate multiple uses
<asp:contentplaceholder id= "Head" runat= "Server" ><%--content reserved location, for sub-page reservation put style sheet, CSS JS location--%>
</asp:ContentPlaceHolder>


<asp:contentplaceholder id= "ContentPlaceHolder1" runat= "server" ><%--reserved location for Web content--%>

</asp:contentplaceholder


Path::::: 4

1: Control path, image, hyperlink, point to Page

First step: On the Wuc.ascx page:
<%--into a server control--%>

Add two items to the control, runat= "Server" id= "ID1", turn the control into a server control, the two things under the user control are indispensable,
Prevents files from being found in the same folder, the server automatically converts the path


2: Style sheet in user Control path take advantage of external style sheet, do not write inline style sheet
First step: Add New item-style sheet
Add a page to the head

Style Sheet page Css.css
#aa {
Background-image:url (.. /image/storm 2015102133868160.jpg);//. /
height:100px;
width:100px

}
Step two: On the Wuc.ascx page:

< div id= "AA" ></div>



3: JS file outside the external resource path, need to call function to handle the path

The first step; add a new item-javascript file
Javascript.js page:
Alert ("Hello");

Step two: WUC.ascx.cs: Write function

public string Showpath ()
{

String path = "Script/javascript.js";
Path = Resolveclienturl (path);//Gets the path URL that the client browser can use
return path;
}

Step Three: Wuc.ascx page: Drag directly over the control

<script src= "<%=showpath ()%>" ></script>


4: Page Path: User control button click on Jump page
User control button to jump page when clicked: Convert relative path to absolute path
~ Represents the root directory of the Web site on the server
protected void Button1_Click (object sender, EventArgs e)
{
Response.Redirect ("~/main.aspx");
}


Pass Value:

One: The page passes the value to the user control:
1. Using FindControl ()

string s = TextBox1.Text;
1. Find the motherboard page
MP mp= this. Master as MP;
2. Use Findcotrol () to find the controls in the master page
TextBox txt = MP. FindControl ("TextBox1") as TextBox;
Txt. Text = s;

B: Attribute passing value
The first step: Write a property inside the user control;
public string Txt
{
Get
{
return TextBox1.Text;
}

Set
{
Textbox1.text=value;
}
}

Step two: Write in the page button
protected void Button1_Click (object sender, EventArgs e)
{

WUC1. TXT = textbox1.text;//The user control with a page value
TextBox1.Text = WUC1. txt;//the page from the user control


}

Step three: When the page control button is clicked:
protected void Button1_Click (object sender, EventArgs e)
{
Locate the properties of the user control
WUC1. TXT = TextBox1.Text;
}




BBBB2: The user control passes the value to the page:
A: Use the session to pass the value:
First step: In the user control:
protected void Button1_Click (object sender, EventArgs e)
{

session["txt"] = TextBox1.Text;
}



Step two: Rewrite the Onloadcomplete () event on the page: Override the method of the parent class in the subclass,
Prevent data delay override Onloadcomplete ()
Rewrite the parent method after the page is loaded and after the page is finished
protected override void Onloadcomplete (EventArgs e)
{
Base. Onloadcomplete (e);

if (session["TXT"]! = NULL)
{
TextBox1.Text = session["txt"]. ToString ();
}
}





Recommended B: Delegate or proxy; Refer to method, refer to method, good but difficult to understand; just change the way you point to it delegete

Dog D=new Dog ();d reference to the object of the dog class
String s= "ssss"; s pointing to a string
public void Show (DOG); Reference point to method, reference to method

1: Define a class
Class Dog
{


public int Dog;
public void walk ();

}
2: Declare a Dog object
Dog D;
3: Point the reference to the dog

D=new Dog ();

4: How to use this reference to tune an object


Proxies: References and events that point to a method are like

Signature: return type void, argument list string s;

Y 1: Define a proxy//user control inside
After adding delegate, Showdelegate is not the original function name but the proxy type name

public delegate void Showdelegate (string s);

2: Declare a reference to a proxy//user control inside

Before adding public, you can use it in other classes.
Public showdelegate Show;


3: Page load on the specific page 3; the proxy reference points to the signature matching (function) method; Can be the same as manually hanging events,
+ = can hang a lot of events, the nature of the event is a special agent. Can point to many methods as long as the signature is consistent,

Show=new showdelegate (DO);

protected void Page_Load (object sender, EventArgs e)
{
Find a master Page
MP MP = this. Master as MP;
To hang a method on an agent
Mp. Show + = GetText;
}

4: Call method with Proxy in User control button

Show ("AA");

protected void Button1_Click (object sender, EventArgs e)
{


. Call the Show method
string s = TextBox1.Text;
Show (s);


4, call function with Proxy
if (show! = null)
{
Show (TextBox1.Text);
}

}

5: Write function on actual page. The signature must be the same as the proxy type
public void do (string s)
{

Textbox1.text=a;
}

Master Board page. Master

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.