ארגומנט שלישי ב- event handler

yoavmardok

New member
ארגומנט שלישי ב- event handler

event handler מקבל באופן אוטומטי שני ארגומנטים כך:
Sub sub_ddlist_pic(ByVal obj As System.Object, ByVal e As System.EventArgs)​
אך אני מעוניין לשלוח ארגומנט שלישי, למשל כך:
Sub sub_ddlist_pic(ByVal obj As System.Object, ByVal e As System.EventArgs, ByVal the_third_arg As String)​
אך כל ניסיונותי נכשלו. כך, למשל כשניסיתי להפעיל את ההנדלר הזה מתוך קונטרול DropDownList:
<asp:DropDownList id="ddlist_pic_1" onselectedindexchanged="sub_ddlist_pic('the string')" runat="server" AutoPostBack="True">​
קיבלתי את הודעת השגיאה הזאת:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30201: Expression expected.​
כנ"ל לגבי כל ניסיון אחר. גם כל החיפושים באינטרנט עלו בתוהו. האם שליחה של יותר משני ארגומנטים ב-event handler היא פשוט בלתי אפשרית?
 

itaym02

New member
אתה יכול להתחכם

אם מדובר בevent שכתבת לבד - תגדיר אותו איך שאתה רוצה. אם מדובר בארוע שכבר מוגדר - תבנה מחלקה שיורשת מEventArgs בתוך המחלקה הזאת תוסיף את הארגומנטים שברצונך להוסיף. זה הסבר כללי - אם תסתבך, תמשיך לשאול.
 

itaym02

New member
תראה - תמשיך לבדוק

הפלטפורמה הזאת כל-כך גדולה, שתמיד יתכן שמפספסים משהו. דר"א, מה הארגומנט השלישי שאתה רוצה להעביר?
 

dan3330

New member
הארגומנט השלישי

מכיל מידע על הפקד השולח (בנוסף ל-ID שמגיע בתוך ב-sender). אגב, מצאתי משהו אחר לשליחת מידע נוסף מהפקד אל ההנדלר:
<asp:button id="Button2" runat="server" Text="Button" CommandArgument="xxxxx"></asp:button> . . . Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Response.Write(sender.commandArgument) End Sub​
העיה שאפשר להשתמש בזה רק בפקדי כפתור כמו Button, LinkButton ו ImageButton. תודה רבה על העזרה!
 
למעלה