פורסם 2006 בדצמבר 319 שנים שלום,יש לי בעיה בשילוב של Web Custom Control ב User Control ב ASP.NET .כתבתי את ה Web Custome Control הבא אשר משמש כ RequiredFieldValidator לפקד Checkbox.using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;namespace CustomValidators //RequiredFieldValidatorForCheckBoxLists{ /// <summary> /// Summary description for WebCustomControl1. /// </summary> public class RequiredFieldValidatorForCheckBoxLists : System.Web.UI.WebControls.BaseValidator { private ListControl _listctrl; private int _restrictionCount; private string _restrictionType; public int restrictionCount { get { return _restrictionCount; } set { _restrictionCount = value; } } public string restrictionType { get { return _restrictionType; } set { _restrictionType = value; } } public RequiredFieldValidatorForCheckBoxLists() { base.EnableClientScript = false; } protected override bool ControlPropertiesValid() { Control ctrl = FindControl(ControlToValidate); if (ctrl != null) { _listctrl = (ListControl) ctrl; return (_listctrl != null); } else return false; // raise exception } protected bool checkit() { int count =0; if(_listctrl.SelectedIndex != -1) { foreach(ListItem li in _listctrl.Items) { if(li.Selected == true) { count++; } } switch (_restrictionType) { case "exactly": if(count == _restrictionCount) { return true; } else { return false; } case "up to": if(count <= _restrictionCount) { return true; } else { return false; } default: return false; } } else { return false; } } protected override bool EvaluateIsValid() { return checkit(); } }}using System;כאשר אני משתמש ב Custom Control הזה ב WEB FORM רגיל, הכל עובד לי כמו שצריך והולידטור הכן עובד.הבעיה שלי היא כאשר אני מנסה להשתמש בולידטור הזה בתוך User Control הוא לא מבצע לי את הוולידציה.אשמח לעזרה בנידון מאחר ואני די תקוע וגילגולי ברשת לא העלו דבר בחקתם.
פורסם 2006 בדצמבר 319 שנים נראה לי שאתה עושה שימוש לא נכון ב- CustomControl ובירושה של BaseValidator בכל אופן אם מה שאתה מנסה לעשות עובד לך ב- דף אבל לא עובד לך תחת UserControlרוב הסיכויים שהבעיה היא ב- ID של ה- control שה- validator צריך לבדוקכאשר שמים control תחת usercontrol ה- ID שלו מורכב מהשם המקורי שנתת לו + קידומת שם ה- usercontrolכיוון שה- ID של אותו control שונה, ה- validator שלך לא מצליח למצוא אותו
פורסם 2006 בדצמבר 319 שנים מחבר הסתכלתי כבר בקוד ה HTML שמוצג למשתמש בדפדן ונכון שיש לו ID מורכב כפי שאתה מציין ID המשולב עם ה ID של ה USER CONTROL וזה ה ID שאני מורה לבצע לו ולידציה Dim myctrlid As String = Me.UniqueID & "_" & mycheck.UniqueIDכאשר זה בעצם נותן לי את _ctl0_check_1_0 למינהם שמתווצרים למשתמש ומופיעים לו ב HTMLוכפי שציינתי זה לא עובד.
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.