protected void ShowMessage(string strMessage)
{
StringBuilder strScript = new StringBuilder();
strScript.Append(“<script language=’javascript’> “);
strScript.Append(“alert(‘” + strMessage + “‘)”);
strScript.Append(“</script>”);
//UpdatePanel內呼叫要用下面的寫法,否則Script不會寫到前端去
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), “testScript”, strScript.ToString(), false);
//一般ServerSide內呼叫
//ClientScript.RegisterStartupScript(this.GetType(), “SetValueScript”, strScript.ToString());
}
protected void ShowMessage(string strMessage)
{
StringBuilder strScript = new StringBuilder();
strScript.Append(“<script language=’javascript’> “);
strScript.Append(“alert(‘” + strMessage + “‘)”);
strScript.Append(“</script>”);
//UpdatePanel內呼叫,否則Script不會寫到前端去
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), “testScript”, strScript.ToString(), false);
//一般ServerSide內呼叫
//ClientScript.RegisterStartupScript(this.GetType(), “SetValueScript”, strScript.ToString());
}
含有 ‘asp.net’標籤(tag)的文章們
27 十月
ShowMessage on Client(ASP.NET)
27 十月
利用Regex檢查是否為數值(ASP.NET)
public bool CheckIsNumber(string val)
{
Regex reNum = new Regex(@”^\d+$”);
bool isNumeric = reNum.Match(val).Success;
return isNumeric;
}
27 十月
DownLoad File From Asp.Net
….
if (file.Exists)
{
//Method-1 將檔案資料讀入Stream,這時檔案已經可以刪除了..之後再把檔案內容輸出即可
//Read File Content
sr = new StreamReader(path);
Response.Clear();
Response.AddHeader(“Content-Disposition”, “attachment; filename=ExcelExport.xls“); //下載的檔案名稱
Response.AddHeader(“Content-Length”, file.Length.ToString()); //下載的檔案大小
Response.ContentType = “application/vnd.ms-excel“; //下載的檔案類型
Response.Write(sr.ReadToEnd());
Response.End();
//Method-2 這是第二個方法,直接把檔案內容寫到前端,此時是不允許將檔案給刪除的,因為檔案是讀取的目標
//Response.Clear();
//Response.AddHeader(“Content-Disposition”, “attachment; filename=ExcelExport.xls”);
//Response.AddHeader(“Content-Length”, file.Length.ToString());
//Response.ContentType = “application/vnd.ms-excel”;
//Response.WriteFile(file.FullName);
//Response.End();
}
….
3 八月
利用FileSteam 讀檔 , 回傳字串資料
//File Content Transfer to String
private String LoadDecodedFile(String file)
{
String DecodedString = “”;
FileStream fs = new FileStream(file, FileMode.Open);
StreamReader r = new StreamReader(fs);
// Position the file pointer at the beginning of the file.
r.BaseStream.Seek(0, SeekOrigin.Begin);
// Read the entire file into a string and decode each chunk.
while (r.Peek() > -1)
DecodedString += Server.HtmlDecode(r.ReadLine());
r.Close();
return DecodedString;
}
17 七月
動態在頁面內新增IFRAME
Dim frame1 As New HtmlControls.HtmlGenericControl
frame1.TagName = “iframe”
frame1.ID = “iframe_” & ugcResult.Index
‘value是一段網址,例如:http://www.ntu.edu.tw
‘或是網站內的位址,例如: ../Common/LiangText.aspx
frame1.Attributes.Add(“src”, value)
Page.Master.Page.Form.Controls.Add(frame1)
30 四月
DataSet欄位運算-超好用
Dim dsUserName As DataSet = spuErp.FillDataset(“tblAuthUser”)
‘增加 GroupID/UserID , GroupName/UserName的欄位
With dsUserName.Tables(0)
.Columns.Add(“Text”, GetType(String), “ISNULL(GroupName,’NoGroupID’)+’/’+UserName”)
[...]
24 四月
取得樹狀結構節點(遞迴)
傳入123時,則回傳 |120|258|269|121|124|123.
使用時,才會利用Split(),拆成字串矩陣
123
120
121
258
269
124
‘判斷是否存在子節點
Dim Arranged() As String = CheckChildNode(MenuID).Split(“|”)
Private Function CheckChildNode(ByVal childMenuID As String) As String
Dim i As Integer = Me.uwtMenu.Find(childMenuID).Nodes.Count
Dim nodeTag As String = “”
If i = 0 Then
nodeTag += “|” & childMenuID
Else
For k As Integer = 0 To i – 1
Dim s As String = Me.uwtMenu.Find(childMenuID).Nodes.Item(k).Tag.ToString
nodeTag [...]