 |
|
|
 |
 |
|
ลองดู link นี้ครับ เผื่อช่วยได้
http://www.velocityreviews.com/forums/t107515-aspnet-20-onmouseover.html
|
 |
 |
 |
 |
Date :
2009-07-28 13:56:22 |
By :
taken |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา class ของผมไปใช้ไฟมครับ
ผมสร้างเป็น custom control
---------------------------------------
RollOveImageButton.cs
Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
namespace MyCustomControls
{
[
DefaultProperty("Text"),
ToolboxData("<{0}:RolloverImageButton runat=\"server\" />")
]
public class RollOverImageButton : ImageButton
{
public RollOverImageButton()
{
//
// TODO: Add constructor logic here
//
}
[
Bindable(true),
Browsable(true),
Category("Appearance"),
DefaultValue(""),
Description("Gets or sets the location of an image to display in the System.Web.UI.WebControls.Image control."),
Localizable(true)
]
public virtual string ImageOverUrl
{
get
{
if (null == ViewState["ImageOverUrl"])
return string.Empty;
else
return Convert.ToString(ViewState["ImageOverUrl"]);
}
set { ViewState["ImageOverUrl"] = value; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute("onmouseover", "this.src='" + base.ResolveClientUrl(ImageOverUrl) + "'");
writer.AddAttribute("onmouseout", "this.src='" + base.ResolveClientUrl(ImageUrl) + "'");
base.AddAttributesToRender(writer);
}
}
}
|
 |
 |
 |
 |
Date :
2009-07-29 17:52:32 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ยังไงครับ ฮ่าๆๆ
|
 |
 |
 |
 |
Date :
2009-07-30 11:29:42 |
By :
nutkit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สร้างเป็น file นามสกุล cs แล้วเอาไปวางไว้ใน folder "App_Code"
วิธีที่ 1 เรียกใช้ใน file code behide
เวลาจะเรียกใช้ก็ต้อง using namespace ก่อน เช่น
using MyCustomControls;
ก็จะมี class RollOverImageButtom มาให้ใช้
ตอนใช้ก็สร้างเป็น Object ก่อน เช่น
RollOverImageButton RollOver = new RollOverImageButton();
มันจะมี method กับ property เหมือนกับ class image buttom เดิม
แต่จะเพิ่ม property "ImageOverUrl" ไว้สำหรับ เวลามี mouse ไปวาง เช่น
RollOver.ImageUrl = "~/images/pic1.gif"; //แสดงรูปปกติ
RollOver.ImageOverUrl = "~/images/pic2.gif"; //แสดงรูปเหมือนมี mouse ไปวาง
2. เรียกใช้ใน file .aspx
ต้อง register ก่อน
<%@ Register TagName="MyControls" Namespace="MyCustomerControls" %>
จากนั้นก็ใช้ได้
<MyControls:RollOverImageButton runat="server" id="RollOver" ImageUrl="~/images/pic1.gif" ImageOverUrl="~/images/pic2.gif" />
จบ
|
 |
 |
 |
 |
Date :
2009-07-30 16:06:59 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองใช้แบบที่ 1 ดูครับ ได้ผลดี
แต่อยากถามเพิ่มนิดหน่อยครับ
คือว่าหน้า Design ผมใช้ <asp:ImageButton ID="ImageButton1" runat="server" />
จะใช้ร่วมกันยังไงครับ รบกวนด้วยนะครับ
|
 |
 |
 |
 |
Date :
2010-03-22 10:45:53 |
By :
memmo12 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ต้องใช้ร่วมกับ imagebutton หรอก
ใช้ rolloverimagebutton เลย รู้ป่าวว่า .net สามารถเขียน controls ใช้เองได้
เจ้า rolloverimagebutton ก็เป็น controls ตัวนึงที่เป็น class ลูกของ imagebutton
โดยเพิ่มคุณสมบัติตอน mouse over เข้าไป
ส่วนวิธีใช้ดู no.4 กับ no.5 ดีๆ จะเข้าใจเอง
|
 |
 |
 |
 |
Date :
2010-03-22 13:22:02 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พยายามดูแล้ว ไม่เข้าใจน่ะครับเพิ่งหัดเขียน .Net
ยังไงรบกวนบอกวิธีที่1
แต่แสดงตรงตำแหน่งที่เราต้องการโดยไม่ต้องสร้างเองได้ไหมครับ
ผมทำแล้วสร้างรูปเอง แต่เอาไปวางในตำแหน่งที่ต้องการไม่ได้
มือใหม่จิงๆ ครับ
ปล.วิธีที่ 2 ผมทำแล้วแต่ไม่ผ่าน
<%@ Register TagName="MyControls" Namespace="MyCustomerControls" %>
แต่พอ
<MyControls:RollOverImageButton runat="server" id="RollOver" ImageUrl="~/images/pic1.gif" ImageOverUrl="~/images/pic2.gif" />
เสร็จ Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'MyControls:RollOverImageButton'.
ใจจิงก็อยากทำแบบที่ 2 แต่ไม่เป็น Y_Y (ผมทำ RollOveImageButton.cs แล้วเอาไปวางไว้ใน folder "App_Code" แล้วครับ)
|
 |
 |
 |
 |
Date :
2010-03-22 14:18:54 |
By :
memmo12 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะพี่ตึ๋งศรี เดวจะเอาไป apply กะ jQuery สะเลยๆๆ ขอบคุณมากค่ะ
|
 |
 |
 |
 |
Date :
2010-03-22 14:33:39 |
By :
blurEye |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มั่วเอาจนได้ ใครมาอ่านทีหลังแล้วยังทำไม่เป็นนะครับลองแบบผมนะ
ใช้วิธีที่ 1 แล้วถ้าต้องการให้รูปที่ต้องการทำ Rollover Image แสดงตามตำแหน่งที่ต้องการ
แก้ไขแค่ หน้า Design ใช้ Label วางตามตำแหน่งที่ต้องการได้เลย
แล้วในหน้า Code แก้ไข
Page.Form.Controls.Add(RollOver);
ให้เปลี่ยนเป็น
ชื่อLabel.Controls.Add(RollOver); <-- แบบนี้ได้เลย
ปล. ผมก็มั่วๆเอา ไม่รู้ว่าเป็นวิธีที่ถูกต้องหรือป่าว แต่มันก็ทำให้ Rollover ได้ลองดูนะครับ ^^
|
 |
 |
 |
 |
Date :
2010-03-22 16:02:14 |
By :
memmo12 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษนะครับ ขอโทษจริงๆ   
ถ้าใครใช้วิธีที่ 2 ไม่ได้ (เขียนลงหน้า design .aspx)
ให้แก้ส่วนของ register ใน attibute tagname เป็น tagprefix ครับ
ตัวอย่าง
Code (C#)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestRollOver.aspx.cs" Inherits="TestRollOver" %>
<%@ Register TagPrefix="MyControls" Namespace="MyCustomControls" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<MyControls:RollOverImageButton ImageUrl="~/images/windman_sprite.gif" ImageOverUrl="~/images/yamatoman_sprite.gif" runat="server" />
</div>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-03-23 08:46:30 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่า tagname เป็น tagprefix ใช้ได้แล้วครับ ขอบคุณครับ นั่งหามาทั้งวันเลยเมื่อวาน
มือใหม่จิงๆ ผม อิอิ
สรุปวิธีที่ 2 นี่มันสุดยอดเลยครับ 
|
 |
 |
 |
 |
Date :
2010-03-23 10:08:47 |
By :
memmo12 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|