Inheritance: ExtenderControlBase
 protected void Page_Load(object sender, EventArgs e)
 {
     // The following sequence of adding controls in the "wrong" order causes
     // an exception when used with the previous databinding implementation
     TextBox tb = new TextBox();
     tb.ID = "tbID";
     Page.Form.Controls.Add(tb);
     TextBoxWatermarkExtender tbwe = new TextBoxWatermarkExtender();
     tbwe.ID = "tbweID";
     tbwe.TargetControlID = tb.ID;
     tbwe.WatermarkText = "WatermarkText";
     Page.Form.Controls.Add(tbwe);
 }
    private void OnTagDataBind(string value, int pos)
    {
        if (string.IsNullOrEmpty(value)) value = "blank";

        string id = string.Format("inputTag_{0}", pos);

        TextBox tb = (TextBox) FindControl(id);

        if (tb != null)
            return;

        tb = new TextBox();
        tb.ID = id;
        tb.CssClass = "sncore_madlib_textbox";

        string qs = Request[value];
        if (!string.IsNullOrEmpty(qs))
        {
            tb.Text = qs;
            tb.Width = qs.Length * 10;
        }
        else
        {
            tb.Width = value.Length * 10;
        }

        Controls.Add(tb);

        TextBoxWatermarkExtender tbex = new TextBoxWatermarkExtender();
        tbex.ID = string.Format("inputTagExtender_{0}", pos);
        tbex.WatermarkText = value;
        tbex.WatermarkCssClass = "sncore_madlib_watermark";
        tbex.TargetControlID = tb.ID;

        Controls.Add(tbex);
    }
 /// <summary>
 /// Disabled the parameter TextBoxWatermarkExtender control.
 /// </summary>
 /// <param name="cbx">The TextBoxWatermarkExtender to disable.</param>
 private void disableWatermark(TextBoxWatermarkExtender twe) {
     twe.Enabled = false;
 }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        #region "Watermark extender"

        // Watermark extender
        // Disable watermark exteder for nonempty fields (issue with value which is same as the watermark text)
        if (!string.IsNullOrEmpty(WatermarkText) && !string.Equals(textbox.Text, WatermarkText, StringComparison.InvariantCulture))
        {
            // Create extender
            TextBoxWatermarkExtender exWatermark = new TextBoxWatermarkExtender();
            exWatermark.ID = "exWatermark";
            exWatermark.TargetControlID = textbox.ID;
            exWatermark.EnableViewState = false;
            Controls.Add(exWatermark);

            // Initialize extender
            exWatermark.WatermarkText = CMSContext.CurrentResolver.ResolveMacros(WatermarkText);
            exWatermark.WatermarkCssClass = textbox.CssClass + " " + ValidationHelper.GetString(GetValue("WatermarkCssClass"), WatermarkCssClass);
        }

        #endregion

        #region "Filter extender"

        if (FilterEnabled)
        {
            // Create extender
            FilteredTextBoxExtender exFilter = new FilteredTextBoxExtender();
            exFilter.ID = "exFilter";
            exFilter.TargetControlID = textbox.ID;
            exFilter.EnableViewState = false;
            Controls.Add(exFilter);

            // Filter extender
            exFilter.FilterInterval = FilterInterval;

            // Set the filter type
            if (FilterTypeValue == null)
            {
                exFilter.FilterType = FilterType;
            }
            else
            {
                if (!string.IsNullOrEmpty(FilterTypeValue))
                {
                    FilterTypes filterType = 0;
                    string[] types = FilterTypeValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (types.Length > 0)
                    {
                        foreach (string typeStr in types)
                        {
                            int type = ValidationHelper.GetInteger(typeStr, 0);
                            switch (type)
                            {
                                case FILTER_NUMBERS:
                                    filterType |= FilterTypes.Numbers;
                                    break;

                                case FILTER_LOWERCASE:
                                    filterType |= FilterTypes.LowercaseLetters;
                                    break;

                                case FILTER_UPPERCASE:
                                    filterType |= FilterTypes.UppercaseLetters;
                                    break;

                                case FILTER_CUSTOM:
                                    filterType |= FilterTypes.Custom;
                                    break;
                            }
                        }
                        exFilter.FilterType = filterType;
                    }
                }
            }

            // Set the filter mode
            object filterModeObj = GetValue("FilterMode");
            if (filterModeObj == null)
            {
                exFilter.FilterMode = FilterMode;
            }
            else
            {
                exFilter.FilterMode = ValidationHelper.GetBoolean(filterModeObj, false) ? FilterModes.InvalidChars : FilterModes.ValidChars;
            }

            // Set valid and invalid characters
            if (exFilter.FilterMode == FilterModes.ValidChars)
            {
                exFilter.ValidChars = ValidChars;
            }
            else
            {
                exFilter.InvalidChars = InvalidChars;
            }
        }

        #endregion

        #region "Autocomplete extender"

        // Autocomplete extender
        if (!string.IsNullOrEmpty(AutoCompleteServiceMethod) && !string.IsNullOrEmpty(AutoCompleteServicePath))
        {
            // Create extender
            AutoCompleteExtender exAuto = new AutoCompleteExtender();
            exAuto.ID = "exAuto";
            exAuto.TargetControlID = textbox.ID;
            exAuto.EnableViewState = false;
            Controls.Add(exAuto);

            exAuto.ServiceMethod = AutoCompleteServiceMethod;
            exAuto.ServicePath = URLHelper.ResolveUrl(AutoCompleteServicePath);
            exAuto.MinimumPrefixLength = AutoCompleteMinimumPrefixLength;
            exAuto.ContextKey = CMSContext.CurrentResolver.ResolveMacros(AutoCompleteContextKey);
            exAuto.CompletionInterval = AutoCompleteCompletionInterval;
            exAuto.EnableCaching = AutoCompleteEnableCaching;
            exAuto.CompletionSetCount = AutoCompleteCompletionSetCount;
            exAuto.CompletionListCssClass = AutoCompleteCompletionListCssClass;
            exAuto.CompletionListItemCssClass = AutoCompleteCompletionListItemCssClass;
            exAuto.CompletionListHighlightedItemCssClass = AutoCompleteCompletionListHighlightedItemCssClass;
            exAuto.DelimiterCharacters = AutoCompleteDelimiterCharacters;
            exAuto.FirstRowSelected = AutoCompleteFirstRowSelected;
            exAuto.ShowOnlyCurrentWordInCompletionListItem = AutoCompleteShowOnlyCurrentWordInCompletionListItem;
        }

        #endregion
    }
Example #5
0
    private void GenerateControls(int seatcount)
    {
        System.Web.UI.WebControls.TextBox           tbname          = null;
        System.Web.UI.WebControls.TextBox           tbage           = null;
        System.Web.UI.WebControls.RadioButtonList   rbGenderM       = null;
        AjaxControlToolkit.TextBoxWatermarkExtender txtWatermark    = null;
        AjaxControlToolkit.TextBoxWatermarkExtender txtWatermarkAge = null;
        RequiredFieldValidator     rfd       = null;
        RequiredFieldValidator     rfdAge    = null;
        RequiredFieldValidator     rfdGender = null;
        RangeValidator             rvdAge    = null;
        RegularExpressionValidator revName   = null;


        Table tblUserDetails = new Table();

        tblUserDetails.ID = "UserDetails";
        TableRow  tr  = new TableRow();
        TableCell tc1 = new TableCell();
        TableCell tc2 = new TableCell();
        TableCell tc3 = new TableCell();

        tc1.Text            = "<span class='text'>Name</span>&nbsp;<span style='color: Red'>*</span>";
        tc2.Text            = "<span class='text'>Gender</span>&nbsp;<span style='color: Red'>*</span>";
        tc2.Width           = 180;
        tc2.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
        tc3.Text            = "<span class='text'>Age</span>&nbsp;<span style='color: Red'>*</span>";

        tr.Controls.Add(tc1);
        tr.Controls.Add(tc2);
        tr.Controls.Add(tc3);
        tblUserDetails.Controls.Add(tr);
        for (int i = 0; i < seatcount; i++)
        {
            TableRow row = new TableRow();

            //dynamically adding controls
            tc1 = new TableCell();
            tc2 = new TableCell();
            tc3 = new TableCell();

            tbname       = new System.Web.UI.WebControls.TextBox();
            tbname.ID    = "txtuser" + i.ToString();
            tbname.Width = 200;

            txtWatermark                   = new AjaxControlToolkit.TextBoxWatermarkExtender();
            txtWatermark.ID                = "txtWaterMark" + i.ToString();
            txtWatermark.WatermarkText     = "Enter Name";
            txtWatermark.WatermarkCssClass = "watermark";
            txtWatermark.TargetControlID   = "txtuser" + i.ToString();

            rfd    = new RequiredFieldValidator();
            rfd.ID = "rfd" + i.ToString();
            rfd.ControlToValidate = "txtuser" + i.ToString();
            rfd.ForeColor         = System.Drawing.Color.Red;
            rfd.ErrorMessage      = "Please enter name";

            revName    = new RegularExpressionValidator();
            revName.ID = "revName" + i.ToString();
            revName.ControlToValidate    = "txtuser" + i.ToString();
            revName.ForeColor            = System.Drawing.Color.Red;
            revName.ValidationExpression = "^[-0-9a-zA-Z ,:.]+$";
            revName.ErrorMessage         = "Alphabets Only";



            rbGenderM    = new System.Web.UI.WebControls.RadioButtonList();
            rbGenderM.ID = "rbGender" + i.ToString();
            rbGenderM.Items.Add("M");
            rbGenderM.Items.Add("F");
            rbGenderM.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;

            rfdGender    = new RequiredFieldValidator();
            rfdGender.ID = "rfdGender" + i.ToString();
            rfdGender.ControlToValidate = "rbGender" + i.ToString();
            rfdGender.ForeColor         = System.Drawing.Color.Red;
            rfdGender.ErrorMessage      = "Choose gender";


            tbage           = new System.Web.UI.WebControls.TextBox();
            tbage.ID        = "txtage" + i.ToString();
            tbage.Width     = 50;
            tbage.MaxLength = 2;

            txtWatermarkAge                   = new AjaxControlToolkit.TextBoxWatermarkExtender();
            txtWatermarkAge.ID                = "txtWaterMarkAge" + i.ToString();
            txtWatermarkAge.WatermarkText     = "Age";
            txtWatermarkAge.WatermarkCssClass = "watermark";
            txtWatermarkAge.TargetControlID   = "txtage" + i.ToString();

            rfdAge    = new RequiredFieldValidator();
            rfdAge.ID = "rfdAge" + i.ToString();
            rfdAge.ControlToValidate = "txtage" + i.ToString();
            rfdAge.ForeColor         = System.Drawing.Color.Red;
            rfdAge.ErrorMessage      = "Enter age";


            rvdAge    = new RangeValidator();
            rvdAge.ID = "rvdAge" + i.ToString();
            rvdAge.ControlToValidate = "txtage" + i.ToString();
            rvdAge.ForeColor         = System.Drawing.Color.Red;
            rvdAge.MinimumValue      = "1";
            rvdAge.MaximumValue      = "99";
            rvdAge.Type         = ValidationDataType.Integer;
            rvdAge.ErrorMessage = "Age between 1-99";

            tc1.Controls.Add(tbname);
            tc1.Controls.Add(txtWatermark);
            tc1.Controls.Add(revName);
            tc1.Controls.Add(new LiteralControl("<br />"));
            tc1.Controls.Add(rfd);

            tc2.Controls.Add(rbGenderM);
            // tc2.Controls.Add(new LiteralControl("<br />"));
            tc2.Width           = 180;
            tc2.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
            tc2.Controls.Add(rfdGender);

            tc3.Controls.Add(tbage);
            tc3.Controls.Add(txtWatermarkAge);
            tc3.Controls.Add(rvdAge);
            tc3.Controls.Add(new LiteralControl("<br />"));
            tc3.Controls.Add(rfdAge);


            row.Controls.Add(tc1);
            row.Controls.Add(tc2);
            row.Controls.Add(tc3);


            tblUserDetails.Controls.Add(row);
        }
        txtPanel.Controls.Add(tblUserDetails);
    }
Example #6
0
 protected override void CreateChildControls()
 {
     Controls.Clear();
     if (!this.DesignMode)
     {
         _textBoxWatermarkExtender = new TextBoxWatermarkExtender();
         _textBoxWatermarkExtender.ID = "_textBoxWatermarkExtender";
         this.Controls.Add(_textBoxWatermarkExtender);
     }
 }