Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between controls and motherboards in ASP.NET

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "ASP.NET controls and motherboard what is the difference", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "what is the difference between controls and motherboard in ASP.NET" this article.

1. The pros and cons of ASP.NET

CodeBehind: mode of "pre-aspx and post-cs"

(1) aspx (control definition, html, css) controls the appearance of the page, and cs controls the program logic

Aspx is a template engine, so you don't need to look for a third-party template engine.

(2. The member level of calling cs in aspx must be protected or public cannot be private.

Because the current this executes the current subclass (see through decompilation)

2 、

Literal:

Mode attribute to avoid XSS attacks

TextBox:

AutopostBack=true focus away from Textbox submission form

In ASP.NET, the form is often submitted by calling the _ doPostBack method instead of calling submit directly

TestChanged event with AutopostBack can click submit to automatically submit the form to update the input text

Button:OnCLientClick

Return confirm ("do you really want to implement it?")

3. Button, LinkButton, and ImageButton let multiple controls share a handler:

Command property set response function

CommandArgument= "daomul" (command parameters pass parameters)

CommandName= "Remove" (name)

4 、

Panal:

Make it into the rendering form of "Advanced Settings" (fieldset): GroupingText= "Advanced Settings"

HyperLink: it is convenient to refer to internal resources within the site (automatic path conversion)

NavigateUrl attribute

5 、

FileUpload:

FileUploadl.HasFile: whether the user has selected a file

FileUploadl.SaveAs ("Root full path"):

Either Server.Mapath or VirtualPathUtility.ToAbsolute is fine

Path=Server.Mapath ("~ / upload/")

Vulnerability: (only files of specified types are allowed to be uploaded)

System.IO.File.Delete (Server.Mapath. ("~ / upload/")

System.IO.File.ReadAllText (Server.Mapath. ("~ / upload/")

6. Example: registration interface

Register.aspx

The copy code is as follows:

Password strength:

.error {background:Red;}

Registered user

$(function () {)

$("#") .blur (function () {

Var str = $(this) .val ()

If (str.length = 1)

{

ErrorMsg.Visible = true

ErrorMsg.Text = "duplicate user name, please re-enter it!"

Return

}

Long userId=Convert.ToInt64 (adapter.InsertUser (txtUserName.Text, txtPassWord.Text)

TxtEmail.Text))

/ / read Session login information

Session ["Login ID"] = userId

Session ["login mark"] = true

/ / set the public jump page where parameters can be passed

/ / function 1: tell the user to register successfully, function 2: prevent the user from clicking to refresh and repeatedly submit data

Response.Redirect ("target.aspx?Msg= registration success is about to turn to login interface & RedirectURL=login.aspx")

}

Protected void txtUserName_TextChanged (object sender, EventArgs e)

{

T_userInfoTableAdapter adapter = new T_userInfoTableAdapter ()

If (adapter.GetDataByUserName (txtUserName.Text). Count > = 1) {

ErrorMsg.Visible = true

ErrorMsg.Text = "duplicate user name, please re-enter it!"

}

Else {

ErrorMsg.Visible = false

}

}

}

}

The regular expression to be used:

Insert data record: INSERT INTO [dbo]. [T_userInfo] ([sUserName], [sPassWord], [Email]) output Inserted.Id VALUES (@ sUserName, @ sPassWord, @ Email)

(1) add SQL statement

(2. Add an output Insert.Id to the Insert statement

(3. Set the ExecuteMode attribute to Scalar

7. The difference of three kinds of controls: html control and server control. Controls for runat=server (preferably)

A1.Attributes ("aaa") = "build attribute assignment"

8. Verify the control

1. RequiredFieldVal:

Set which control and display name (and CausesValdation focus away)-empty

Initial value: InitleValue (please enter keywords, including the initial value of the drop-down box)

Validator commonness

!

If (! IsValid) {return;}

If (this.IsValid) {/ / prevent skipping client-side verification IsValid indicates whether all Validator in the page have passed

Label1.Text= ""

}

Else {

Label1.Text= "insufficient or incorrect client"

}

ValidstionGroup grouping (the form can be submitted by a single group within the page, but not associated with other groups) is the same as the name of the button

(2. RangeValidator: range verification

Maximum and minimum comparison

Under Date.Now. () baidu

(3. Only RequiredFieldValidator can verify that the field is empty

(4. CompareValidator: compare verification (type check, compare with other controls,)

ControlToCompare is set to the control to be compared

RegularExpression:

VaildationExpression regular expression validation

CustomVaildate Custom Control validation

ServerValidate server verification code

ClientVlidtionFunction

(5. ValidationSummary summarizes error messages

The difference between text and ErrorMsg, ErrorMsg is used in ValidationSummary

The text is displayed directly in the location of the validation control.

Master:

/ / controls for manipulating template pages

Button btn= (Button) this.Master.FindControl ("Button1")

Btn.Visiblebones! Btn.Vissble

This.Master.Mapath ()

The virtual path is converted to the path accessed by the client (not a server control):

Src= ""

This.ResolveClientUrl ()

ResolveClientUrl: consider the path of the current page

ResolveUrl: generate a path from the root

These are all the contents of this article entitled "what is the difference between controls and motherboards in ASP.NET?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report