header image

.Net Settings Note

SERVER VARIABLES:
(appSettings 區段通常放在 connectionStrings 區段的上面)

using System.Web.Configuration; //WebConfigurationManager的命名空間必須

//抓 AppSettings 範例
string strWebName = WebConfigurationManager.AppSettings[“WebName”];

//抓 ConnectionString 範例
string strConnString = WebConfigurationManager.ConnectionStrings[“Connection”];
=================================================
CREATE FRONTEND ELEMENT FROM BEHIND CODE:
HtmlGenericControl div = new HtmlGenericControl(“div”);
div.Attributes.Add(“id”, divID);
div.Attributes.Add(“style”, “background-color:” + BackColorCode + “; color: ” + textColorCode + “;”);
return div;
=================================================
THE WAY DESIGN TO CHECK CHECKBOXS IN WEB:
function showUnchecked() {
$(‘.user_checkbox:input:checkbox’).each(
function () {
if ($(this).is(‘:checked’)) {
alert($(this).attr(‘id’) + ” is checked!”);
}
else {
alert($(this).attr(‘id’) + ” is not checked!”);
}
});
}
function disableUser(userAccount) {
var c = “input[id='” + userAccount + “‘]”;
if ($(c).is(‘:checked’)) {
alert(‘chb checked’);
} else {
alert(‘chb not checked’);
}
=================================================
GET URL FROM BEHIND CODE:
hid_PageURL_index.Value = Request.Url.AbsoluteUri;
=================================================
HOW TO ACCESS HTML ELEMENTS IN WEB FROM BEHIND CODE:
Request.From[“btn01”];
=================================================
TO CHECK A STRING THAT DIDN’T EVEN EXIST:
String.IsNullOrEmpty(Request.QueryString[“CODE”])
=================================================
USE BEHIND CODE TO CALL JAVASCRIPT FUNCTION:
ScriptManager.RegisterStartupScript(this, typeof(Page), “UpdateMsg”, “alert(‘Error occurs…’)”, true);
=================================================
前端 Session使用法

=================================================
因為 ASP.NET 網頁加上 masterpage時,為了讓每個控制項的id是唯一的,
所以在編譯後render出來的頁面,每個ASP控制項的id都會被附予新的id