PDA

View Full Version : استفاده از event های سمت سرور در کنترل های html ای



shirin_sh1024
چهارشنبه 30 تیر 1389, 19:16 عصر
سلام
در کنترل های سرور ساید برای اینکه بخوایم با کلیک شدن روی اون کنترل مثلا به صفحه دیگه ای کاربر هدایت بشه روی اون کنترل کلیک میکنیم و event مربوط به اون در سمت سرور ساخته میشه و با دستور response.redirect کاربر رو به صفحه ای که میخوایم میفرستیم
اگه بخوایم همین کار رو برای کنترل های html ای انجام بدیم باید چطوری انجامش داد؟
در واقع من یه img دارم که با جی کوئری روش افکت گذاشتم حالا میخوام وقتی روش کلیک میشه کاربر به صفحه دیگه ای بره بهترین روش واسه انجام این کار چیه؟

Peyman.Gh
چهارشنبه 30 تیر 1389, 19:29 عصر
<img onclick="window.location='YourPage.aspx'" src=""/>

shirin_sh1024
چهارشنبه 30 تیر 1389, 19:46 عصر
ممنون آقا پیمان مشکلم حل شد :لبخندساده:
فقط یه سئوال ، اصلا امکانش هست بشه به event های این کنترل ها مثله کنترل های سرور سایت در code behind دسترسی داشت و اونجا در event ها کد نوشت؟ مثلا اگه runat سرور بشند میشه باهاشون مثله یه کنترل سرور ساید رفتار کرد؟(و اگه میشه چطوری؟) یا فقط میشه از جاوا اسکریپت استفاده کرد؟

Peyman.Gh
چهارشنبه 30 تیر 1389, 20:00 عصر
مثلا اگه runat سرور بشند میشه باهاشون مثله یه کنترل سرور ساید رفتار کرد؟(و اگه میشه چطوری؟)


<img runat=server id="img"/>

protected void Page_Load(object sender, EventArgs e)
{
img.Src = "~/image/1.jpg";
}

shirin_sh1024
چهارشنبه 30 تیر 1389, 20:24 عصر
درسته ولی در کدی که نوشتید src پروپرتی هست که الان در event ، page load صفحه بهش مقدار دادید . سئوال من در مورد event هاست اینکه میشه در code behind متدی مثله متد کلیک کنترل ها برای کنترل های html ای در سمت سرور داشت؟
یه چیزی شبیه به این:




protected void Button1_Click(object sender, EventArgs e)
{
}


این متد کلیک برای یک botton هستش ولی من میخوام همچین متدی برای مثال برای یک input یا img داشته باشم

Peyman.Gh
چهارشنبه 30 تیر 1389, 20:30 عصر
<img runat=server id="img"/>

protected void Page_Load(object sender, EventArgs e)
{
img.Attributes.Add("onclick", "window.location='YourPage.aspx'");
}

hosseinrahmatei
چهارشنبه 30 تیر 1389, 20:33 عصر
دوست عزیز کنترل های html اگر ranut برابر با Server باشد مثل کنترل های دکمه ، تکس باکس و... دارای دو رویداد سمت سرور می باشند که
1- server click
2- server change
که می توان کد مربوطه را در ان قرار داد

shirin_sh1024
چهارشنبه 30 تیر 1389, 20:58 عصر
دوست عزیز کنترل های html اگر ranut برابر با Server باشد مثل کنترل های دکمه ، تکس باکس و... دارای دو رویداد سمت سرور می باشند که
1- server click
2- server change
که می توان کد مربوطه را در ان قرار داد


یه کم بیشتر توضیح میدید؟ این دو تا رویدادی که فرمودین رو از کجا باید بیارم؟
در code behind باید دستی بنویسم؟

hosseinrahmatei
چهارشنبه 30 تیر 1389, 21:14 عصر
یه کم بیشتر توضیح میدید؟ این دو تا رویدادی که فرمودین رو از کجا باید بیارم؟
در code behind باید دستی بنویسم؟
دوست عزیز شما به طور مثال وقتی یک دکمه html را ranut را برابر server قرار دادید به بخش design رفته و روی دکمه مورد نظر دوبار کلیک کنید خودش رویداد مربوطه را می اورد
یا در بخش کد بیهایند بروید و کنترل مورد نظر را انتخاب و سپس رویدادهای ان را میتوانید مشاهده کنید

Web.Designer01
پنج شنبه 31 تیر 1389, 17:00 عصر
<img onclick="window.location='YourPage.aspx'" src=""/>
درست کار میکنه، فقط چرا کرسر موس شبیه دست نمیشه؟!
یعنی مشخص نیست که روی لینک هستیم.

shirin_sh1024
پنج شنبه 31 تیر 1389, 17:11 عصر
چرا کرسر موس شبیه دست نمیشه؟!
فکر کنم با جی کوئری بشه درستش کرد
یادمه یه جا همچین چیزی رو تو جی کوئری دیدم که وقی موس بره رو یه کنترلی بتونی تعیین کنی موس به چه شکلی دربیاد

Alireza_Salehi
پنج شنبه 31 تیر 1389, 17:16 عصر
باید یک کلاس به این img بدهید و درحالت hover تعیین کنید که کرسر موس عوض شود.

<img onclick="window.location='YourPage.aspx'" src=""/ class="imgclass">


.imgclass:hover{cursor:pointer}

Peyman.Gh
پنج شنبه 31 تیر 1389, 17:25 عصر
فکر کنم با جی کوئری بشه درستش کردنیازی به Jquery نمیباشد.

<img onclick="window.location='YourPage.aspx'" src="" style="cursor:pointer;"/>

BahmanDB
پنج شنبه 31 تیر 1389, 17:53 عصر
کپی شده از MSDN





DHTML Events
This section contains the events exposed by the Dynamic HTML (DHTML) Object Model.
Events

onabort (http://msdn.microsoft.com/en-us/library/ms536785%28v=VS.85%29.aspx) Fires when the user aborts the download.
onactivate (http://msdn.microsoft.com/en-us/library/ms536787%28v=VS.85%29.aspx) Fires when the object is set as the active element (http://msdn.microsoft.com/en-us/library/ms533065%28v=VS.85%29.aspx).
onafterprint (http://msdn.microsoft.com/en-us/library/ms536788%28v=VS.85%29.aspx) Fires on the object immediately after its associated document prints or previews for printing.
onafterupdate (http://msdn.microsoft.com/en-us/library/ms536790%28v=VS.85%29.aspx) Fires on a databound object after successfully updating the associated data in the data source object.
onbeforeactivate (http://msdn.microsoft.com/en-us/library/ms536791%28v=VS.85%29.aspx) Fires immediately before the object is set as the active element.
onbeforecopy (http://msdn.microsoft.com/en-us/library/ms536901%28v=VS.85%29.aspx) Fires on the source object before the selection is copied to the system clipboard.
onbeforecut (http://msdn.microsoft.com/en-us/library/ms536902%28v=VS.85%29.aspx) Fires on the source object before the selection is deleted from the document.
onbeforedeactivate (http://msdn.microsoft.com/en-us/library/ms536903%28v=VS.85%29.aspx) Fires immediately before the activeElement (http://msdn.microsoft.com/en-us/library/ms533065%28v=VS.85%29.aspx) is changed from the current object to another object in the parent document.
onbeforeeditfocus (http://msdn.microsoft.com/en-us/library/ms536904%28v=VS.85%29.aspx) Fires before an object contained in an editable element enters a UI-activated state or when an editable container object is control selected.
onbeforepaste (http://msdn.microsoft.com/en-us/library/ms536905%28v=VS.85%29.aspx) Fires on the target object before the selection is pasted from the system clipboard to the document.
onbeforeprint (http://msdn.microsoft.com/en-us/library/ms536906%28v=VS.85%29.aspx) Fires on the object before its associated document prints or previews for printing.
onbeforeunload (http://msdn.microsoft.com/en-us/library/ms536907%28v=VS.85%29.aspx) Fires prior to a page being unloaded.
onbeforeupdate (http://msdn.microsoft.com/en-us/library/ms536908%28v=VS.85%29.aspx) Fires on a databound object before updating the associated data in the data source object.
onblur (http://msdn.microsoft.com/en-us/library/ms536909%28v=VS.85%29.aspx) Fires when the object loses the input focus.
onbounce (http://msdn.microsoft.com/en-us/library/ms536910%28v=VS.85%29.aspx) Fires when the behavior (http://msdn.microsoft.com/en-us/library/ms533502%28v=VS.85%29.aspx) property of the marquee (http://msdn.microsoft.com/en-us/library/ms535851%28v=VS.85%29.aspx) object is set to "alternate" and the contents of the marquee reach one side of the window.
oncellchange (http://msdn.microsoft.com/en-us/library/ms536911%28v=VS.85%29.aspx) Fires when data changes in the data provider.
onchange (http://msdn.microsoft.com/en-us/library/ms536912%28v=VS.85%29.aspx) Fires when the contents of the object or selection have changed.
onclick (http://msdn.microsoft.com/en-us/library/ms536913%28v=VS.85%29.aspx) Fires when the user clicks the left mouse button on the object.
oncontextmenu (http://msdn.microsoft.com/en-us/library/ms536914%28v=VS.85%29.aspx) Fires when the user clicks the right mouse button in the client area, opening the context menu.
oncontrolselect (http://msdn.microsoft.com/en-us/library/ms537844%28v=VS.85%29.aspx) Fires when the user is about to make a control selection of the object.
oncopy (http://msdn.microsoft.com/en-us/library/ms536916%28v=VS.85%29.aspx) Fires on the source element when the user copies the object or selection, adding it to the system clipboard.
oncut (http://msdn.microsoft.com/en-us/library/ms536917%28v=VS.85%29.aspx) Fires on the source element when the object or selection is removed from the document and added to the system clipboard.
ondataavailable (http://msdn.microsoft.com/en-us/library/ms536918%28v=VS.85%29.aspx) Fires periodically as data arrives from data source objects that asynchronously transmit their data.
ondatasetchanged (http://msdn.microsoft.com/en-us/library/ms536919%28v=VS.85%29.aspx) Fires when the data set exposed by a data source object changes.
ondatasetcomplete (http://msdn.microsoft.com/en-us/library/ms536920%28v=VS.85%29.aspx) Fires to indicate that all data is available from the data source object.
ondblclick (http://msdn.microsoft.com/en-us/library/ms536921%28v=VS.85%29.aspx) Fires when the user double-clicks the object.
ondeactivate (http://msdn.microsoft.com/en-us/library/ms536922%28v=VS.85%29.aspx) Fires when the activeElement is changed from the current object to another object in the parent document.
ondrag (http://msdn.microsoft.com/en-us/library/ms536923%28v=VS.85%29.aspx) Fires on the source object continuously during a drag operation.
ondragend (http://msdn.microsoft.com/en-us/library/ms536924%28v=VS.85%29.aspx) Fires on the source object when the user releases the mouse at the close of a drag operation.
ondragenter (http://msdn.microsoft.com/en-us/library/ms536925%28v=VS.85%29.aspx) Fires on the target element when the user drags the object to a valid drop target.
ondragleave (http://msdn.microsoft.com/en-us/library/ms536926%28v=VS.85%29.aspx) Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.
ondragover (http://msdn.microsoft.com/en-us/library/ms536927%28v=VS.85%29.aspx) Fires on the target element continuously while the user drags the object over a valid drop target.
ondragstart (http://msdn.microsoft.com/en-us/library/ms536928%28v=VS.85%29.aspx) Fires on the source object when the user starts to drag a text selection or selected object.
ondrop (http://msdn.microsoft.com/en-us/library/ms536929%28v=VS.85%29.aspx) Fires on the target object when the mouse button is released during a drag-and-drop operation.
onerror (http://msdn.microsoft.com/en-us/library/ms536930%28v=VS.85%29.aspx) Raised when there is an error that prevents the completion of the cross-domain request.
onerror (http://msdn.microsoft.com/en-us/library/cc197053%28v=VS.85%29.aspx) Fires when an error occurs during object loading.
onerrorupdate (http://msdn.microsoft.com/en-us/library/ms536931%28v=VS.85%29.aspx) Fires on a databound object when an error occurs while updating the associated data in the data source object.
onfilterchange (http://msdn.microsoft.com/en-us/library/ms536932%28v=VS.85%29.aspx) Fires when a visual filter changes state or completes a transition.
onfinish (http://msdn.microsoft.com/en-us/library/ms536933%28v=VS.85%29.aspx) Fires when marquee looping is complete.
onfocus (http://msdn.microsoft.com/en-us/library/ms536934%28v=VS.85%29.aspx) Fires when the object receives focus.
onfocusin (http://msdn.microsoft.com/en-us/library/ms536935%28v=VS.85%29.aspx) Fires for an element just prior to setting focus on that element.
onfocusout (http://msdn.microsoft.com/en-us/library/ms536936%28v=VS.85%29.aspx) Fires for the current element with focus immediately after moving focus to another element.
onhashchange (http://msdn.microsoft.com/en-us/library/cc288209%28v=VS.85%29.aspx) Raised when there are changes to the portion of a URL that follows the number sign (#).
onhelp (http://msdn.microsoft.com/en-us/library/ms536937%28v=VS.85%29.aspx) Fires when the user presses the F1 key while the browser is the active window.
onkeydown (http://msdn.microsoft.com/en-us/library/ms536938%28v=VS.85%29.aspx) Fires when the user presses a key.
onkeypress (http://msdn.microsoft.com/en-us/library/ms536939%28v=VS.85%29.aspx) Fires when the user presses an alphanumeric key.
onkeyup (http://msdn.microsoft.com/en-us/library/ms536940%28v=VS.85%29.aspx) Fires when the user releases a key.
onlayoutcomplete (http://msdn.microsoft.com/en-us/library/ms536941%28v=VS.85%29.aspx) Fires when the print or print preview layout process finishes filling the current LayoutRect (http://msdn.microsoft.com/en-us/library/aa969430%28v=VS.85%29.aspx) object with content from the source document.
onload (http://msdn.microsoft.com/en-us/library/ms536942%28v=VS.85%29.aspx) Raised when the object has been completely received from the server.
onload (http://msdn.microsoft.com/en-us/library/cc197055%28v=VS.85%29.aspx) Fires immediately after the browser loads the object.
onlosecapture (http://msdn.microsoft.com/en-us/library/ms536943%28v=VS.85%29.aspx) Fires when the object loses the mouse capture.
onmessage (http://msdn.microsoft.com/en-us/library/cc197057%28v=VS.85%29.aspx) Fires when the user sends a cross-document message with postMessage (http://msdn.microsoft.com/en-us/library/cc197015%28v=VS.85%29.aspx).
onmousedown (http://msdn.microsoft.com/en-us/library/ms536944%28v=VS.85%29.aspx) Fires when the user clicks the object with either mouse button.
onmouseenter (http://msdn.microsoft.com/en-us/library/ms536945%28v=VS.85%29.aspx) Fires when the user moves the mouse pointer into the object.
onmouseleave (http://msdn.microsoft.com/en-us/library/ms536946%28v=VS.85%29.aspx) Fires when the user moves the mouse pointer outside the boundaries of the object.
onmousemove (http://msdn.microsoft.com/en-us/library/ms536947%28v=VS.85%29.aspx) Fires when the user moves the mouse over the object.
onmouseout (http://msdn.microsoft.com/en-us/library/ms536948%28v=VS.85%29.aspx) Fires when the user moves the mouse pointer outside the boundaries of the object.
onmouseover (http://msdn.microsoft.com/en-us/library/ms536949%28v=VS.85%29.aspx) Fires when the user moves the mouse pointer into the object.
onmouseup (http://msdn.microsoft.com/en-us/library/ms536950%28v=VS.85%29.aspx) Fires when the user releases a mouse button while the mouse is over the object.
onmousewheel (http://msdn.microsoft.com/en-us/library/ms536951%28v=VS.85%29.aspx) Fires when the wheel button is rotated.
onmove (http://msdn.microsoft.com/en-us/library/ms536952%28v=VS.85%29.aspx) Fires when the object moves.
onmoveend (http://msdn.microsoft.com/en-us/library/ms536953%28v=VS.85%29.aspx) Fires when the object stops moving.
onmovestart (http://msdn.microsoft.com/en-us/library/ms536954%28v=VS.85%29.aspx) Fires when the object starts to move.
onoffline (http://msdn.microsoft.com/en-us/library/cc304126%28v=VS.85%29.aspx) Raised when Windows Internet Explorer is working offline.
ononline (http://msdn.microsoft.com/en-us/library/cc304127%28v=VS.85%29.aspx) Raised when Internet Explorer is working online.
onpage (http://msdn.microsoft.com/en-us/library/dd758072%28v=VS.85%29.aspx) Not implemented.
onpaste (http://msdn.microsoft.com/en-us/library/ms536955%28v=VS.85%29.aspx) Fires on the target object when the user pastes data, transferring the data from the system clipboard to the document.
onprogress (http://msdn.microsoft.com/en-us/library/cc197058%28v=VS.85%29.aspx) Raised when the browser starts receiving data from the server.
onpropertychange (http://msdn.microsoft.com/en-us/library/ms536956%28v=VS.85%29.aspx) Fires when a property changes on the object.
onreadystatechange (http://msdn.microsoft.com/en-us/library/dd576252%28v=VS.85%29.aspx) Sets or retrieves the event handler for asynchronous requests.
onreadystatechange (http://msdn.microsoft.com/en-us/library/ms536957%28v=VS.85%29.aspx) Fires when the state of the object has changed.
onreset (http://msdn.microsoft.com/en-us/library/ms536958%28v=VS.85%29.aspx) Fires when the user resets a form.
onresize (http://msdn.microsoft.com/en-us/library/ms536959%28v=VS.85%29.aspx) Fires when the size of the object is about to change.
onresizeend (http://msdn.microsoft.com/en-us/library/ms536960%28v=VS.85%29.aspx) Fires when the user finishes changing the dimensions of the object in a control selection.
onresizestart (http://msdn.microsoft.com/en-us/library/ms536961%28v=VS.85%29.aspx) Fires when the user begins to change the dimensions of the object in a control selection.
onrowenter (http://msdn.microsoft.com/en-us/library/ms536962%28v=VS.85%29.aspx) Fires to indicate that the current row has changed in the data source and new data values are available on the object.
onrowexit (http://msdn.microsoft.com/en-us/library/ms536963%28v=VS.85%29.aspx) Fires just before the data source control changes the current row in the object.
onrowsdelete (http://msdn.microsoft.com/en-us/library/ms536964%28v=VS.85%29.aspx) Fires when rows are about to be deleted from the recordset.
onrowsinserted (http://msdn.microsoft.com/en-us/library/ms536965%28v=VS.85%29.aspx) Fires just after new rows are inserted in the current recordset.
onscroll (http://msdn.microsoft.com/en-us/library/ms536966%28v=VS.85%29.aspx) Fires when the user repositions the scroll box in the scroll bar on the object.
onselect (http://msdn.microsoft.com/en-us/library/ms536967%28v=VS.85%29.aspx) Fires when the current selection changes.
onselectionchange (http://msdn.microsoft.com/en-us/library/ms537845%28v=VS.85%29.aspx) Fires when the selection state of a document changes.
onselectstart (http://msdn.microsoft.com/en-us/library/ms536969%28v=VS.85%29.aspx) Fires when the object is being selected.
onstart (http://msdn.microsoft.com/en-us/library/ms536970%28v=VS.85%29.aspx) Fires at the beginning of every loop of the marquee object.
onstop (http://msdn.microsoft.com/en-us/library/ms536971%28v=VS.85%29.aspx) Fires when the user clicks the Stop button or leaves the Web page.


onstorage (http://msdn.microsoft.com/en-us/library/cc197059%28v=VS.85%29.aspx)

Fires when a DOM Storage area is updated.
onstoragecommit (http://msdn.microsoft.com/en-us/library/cc197060%28v=VS.85%29.aspx) Fires when a local DOM Storage area is written to disk.
onsubmit (http://msdn.microsoft.com/en-us/library/ms536972%28v=VS.85%29.aspx) Fires when a FORM (http://msdn.microsoft.com/en-us/library/ms535249%28v=VS.85%29.aspx) is about to be submitted.
ontimeout (http://msdn.microsoft.com/en-us/library/cc197061%28v=VS.85%29.aspx) Raised when there is an error that prevents the completion of the request.
onunload (http://msdn.microsoft.com/en-us/library/ms536973%28v=VS.85%29.aspx) Fires immediately before the object is unloaded.