Random rnd1 = new Random(); int month = rnd1.Next(1, 13); // 產生介於 1~12 的亂數 int number = rnd1.Next(100); // 產生介於 0~99 的亂數
2013年2月17日 星期日
2013年2月11日 星期一
在 MasterPage 中使用 PreviousPage.FindControl
假設 source.aspx 包含兩個控制項,例如:
目標頁面 target.aspx :
接著想在 target.aspx 中使用
then in target.aspx.cs:
如此則按下 source.aspx 的 Button 後,會在 target.aspx 中的 Label 顯示 Input 欄位的值。
但如果頁面是 MasterPage 裡的 ContentPage,則失效 (取到 null )。
解法:
透過
上面的 target.aspx.cs 改為:
參考: http://www.aspnet101.com/2008/01/using-previouspage-with-a-master-page/
<asp:TextBox ID="myBox" runat="server" /> <asp:Button ID="btn" runat="server" Text="click me" onclick="btn_Click" />in source.aspx.cs:
protected void btn_Click(object sender, EventArgs e) {
Server.Transfer("target.aspx");
}
目標頁面 target.aspx :
<asp:Label ID="myLabel" runat="server" Text="default_text" />
接著想在 target.aspx 中使用
PreviousPage.FindControl 取得 source.aspx 的 TextBox 值,則要加入:<%@ PreviousPageType VirtualPath="~/source.aspx" %>
then in target.aspx.cs:
if(Page.PreviousPage != null){
var textbox = (TextBox) Page.Previous.FindControl("myBox");
Label1.Text = textbox.Text;
}如此則按下 source.aspx 的 Button 後,會在 target.aspx 中的 Label 顯示 Input 欄位的值。
但如果頁面是 MasterPage 裡的 ContentPage,則失效 (取到 null )。
解法:
透過
ContentPlaceHolderID,先找到 Content,再取控制項。上面的 target.aspx.cs 改為:
if(Page.PreviousPage != null){
var preContent = (ContentPlaceHolder)
Page.PreviousPage.Master.FindControl("myContentPlaceHolderID");
TextBox textbox = (TextBox) preContent.FindControl("myBox");
Label1.Text = textbox.Text;
}
參考: http://www.aspnet101.com/2008/01/using-previouspage-with-a-master-page/
2013年2月4日 星期一
ASP.NET 取得 Master Page 的控制項
指定文字:
in MasterPage:
in ContentPage.:
指定class:
in MasterPage:
in ContentPage:
指定單一屬性:
in MasterPage:
<asp:Label id="label1" runat="server"/> <input type="text" id="textbox1" runat="server"/>
in ContentPage.:
Label myLabel = (Label)Master.FindControl("label1");
myLabel.Text = "get ASP Label";
HtmlInputControl myBox = (HtmlInputControl)Master.FindControl("textbox1")
myBox.Value = "get Html TextBox";
指定class:
in MasterPage:
<ul id="List" runat="server"> <li id="listItem1" runat="server"><a href="#">myLink</a></li> </ul>
in ContentPage:
HtmlGenericControl myList = (HtmlGenericControl)Master.FindControl("listItem1");
myList.Attributes.Add("class", "currentClassName");
指定單一屬性:
myList.Style.Add("background-color", "currentColor");2012年11月28日 星期三
jQuery 選擇器 ( Selector )
變更input欄位的值:
$("input").val("newText");
變更選取id的值:$("#myId").val("newText");
變更id:$("#myId").attr("id", "newId");
變更class:$("#myId").attr("class", "newClass");
移除class:$("#myId").removeClass("myClass");
取得第n個元素:$("tr:eq(2)") // 取得第3個tr 使用變數:var index = 5;
$("input[type=text]:eq("+index+")") // 取得第6個textbox 變數必須以雙引號包
取得前n個元素:$("a").slice(0, 10) // 取前10個a class篩選:$("tr[class!='pager']") // 取得class不是pager的tr
2012年11月7日 星期三
Loop Insert
DECLARE @counter int;
SET @counter = 0;
while(@counter<10)
BEGIN;
SET @counter = @counter + 1;
INSERT INTO myTable
(myColumn)
VALUES
('number' + CAST(@counter as varchar))
END;
訂閱:
文章 (Atom)