C hash Web application primer classic study notes 2

  • 2020-05-05 11:06:08
  • OfStack

Read Web.config to set

      Conn   =   new   SqlConnection(ConfigurationSettings AppSettings[" cnFriends ConnectString "]);

 

    < appSettings >

        < !--       User   application   and   configured   property   settings   go   here.-- >

        < !--       Example:   < add   key="settingName"   value="settingValue"/ >   -- >

< add   key="cnFriends.ConnectionString"   value="data   source=(local)\NetSdk;initial   catalog=FriendsData;user   id=sa"   / >     < /appSettings >

 


Several namespaces

When using DataSet, using   system.Data.SqlClient

When configuring Web.config, using   system.Configuration
is used

This reminds me of my freshman year when I studied C
bool   visible

btnSearch.Text   =   visible?   "New   Search"  :   "Search"  ;


This is also good

"Users" dsResult. tables []. rows. count

Conver. Tonint32 (ConfigurationSettings. AppSettings [" Cokuale. number] ");


Hard enough 1: save the result with Session and bind

Session[" Search "]   =   dsResults;

dsResults   =   (DataSet)   Session[" Search "];

grdResults.DataBind();
Actually, Session, Application deposit is object   type, therefore, the final will be
explicit conversion type And, by the way, whether you get a value of string type is determined by null  .

Hard enough 2: select row
from DataTable
DataRow[]   rows   =   dsResults.Tables[" Users "].Select(filter);

dsResults   =   dsResults.Clone();

foreach(DataRow   row   in   rows)

{

              dsResults.Tables[" Tables "].ImportRow(row);

}


Gets a control on webForm  ,

ImageButton   img   =   (ImageButton)e Item FindControl(" Selectbutton ")


Jump:

Server. Transfer (" Caoxicao. aspx ");


Server control adds js script (Attributes property)

imgShow.Attributes.Add(" onclick ", "document.getElementById(' tbPrefs').style.display   =   'block'; );
Again (Style attribute),

img. Style. Add (" Cursor ", 'Pointer');


Color related:

ColorConvert   cv   =   new   ColorConvert();

Color   selected   =   Color.Empty;

Selected   =   (olor)cv.ConvertFromString(White);


Increase Cookie

Response. Cookies. Add (new   HttpCookie (" backColor ", r)


My favorite -- the user control

Using   FriendsReunion.Controls;

Protectd   override   void   Oninit(EventArgs   e)

{

                =   (FriendsFooter)LoadControl(Request ApplicationPath+ "/Controls   FriendsFooter aspx");

                  SubHeader   _subHeader   =   new   SubHeader();

}

Page.Contros.AddAt(0,_footer);

Page.Contros.AddAt(0,_subHeader);

base.OnInit(e);

}


Create a new Html control instance,

HtmlGenericControl   div   =   new   HtmlGenericControl(" div ");

div. Style. Add (" background - color ", bg);

This class is used to represent   HTML   server control markup that is not directly represented by the  .NET   Framework   class, such as   < span > , < div > , < body >   and   < font >


Return DataSet

Public   DataSet   Contact()

{

          String   =   "@  Select   *   from  ...  ..." ;

                  DataSet   requests   =   new   DataSet();

                  New   SqlDtaAdapter   (sql,conn).Fill(requests);

                  //return   requests.GetXml();
                                      Return   requests;

}

Receive :(when the return value is a data set in Xml format)

DataSet   results   =   new   DataSet();

Results.ReadXml(new   StringReader(fi.ContactRequest(userid)));


When using WebService, simply add the [WebMethod] feature to the method!

If the cache is added, [WebMethod(CacheDurition=600)]

Instantiate WebService

FriendsService.FriendsInfo   fi   =   new   FriendsService.FriendsInfo();

String   userid;

Userid   =   fi.GetUserID("... ") );


Small Tips!

HyperLink   reg   =   new   HyperLink();

Reg.ToolTip   =   "...  ..." ;


Checkout:

System.Web.Security.Forms.Authentication.SignOut();

Response.write   (Request.ApplicaltionPath);


Trace debugging:

Trace.Write

Trace.Warn


Exception:

1.       throws an exception

                program throws
exception
              Throw new   ***Exception("... ") );

2.       catches exceptions

                must be thrown from an try code block to begin with, and try code block to place all the code that might throw an exception.

Eg:

                  Try

                                    {

                             ...  ...

                                    }

                  Catch(ArgumentNullExeption   e)

                                    {

                               ...

                                    }

 

web.config sets

< Custom   Errors mode   =   "on" defaultRedriect   = customerror aspx;  />


Related articles: