This is a migrated thread and some comments may be shown as answers.

I want to access the RequiredFieldValidator in the detailed RadGrid using a control in the same row

3 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 2
Mohamed asked on 03 Oct 2011, 08:49 AM
I've hierarchy  grid with a runtime controls in the details of each row,
There's a checkbox control in the last column.
and there's a textbox and a validator in the second column
------------------------------------------------------------------------------------------------------------------------------------
Label with name Please type a valuePlease Enter Only Numbers
-------------------------------------------------------------------------------------------------------------------------------------
All these controls are runtime controls built in the "_ItemDataBound" event.
-------------------------------------------------------------------------------------------------------------------------------------
 if (e.Item is GridDataItem)
            {
                if (e.Item.OwnerTableView.Name == "GroupPoints")
                {
                            RequiredFieldValidator rv = new RequiredFieldValidator();
                            rv.ID = "RequiredFieldValidator4";
                            rv.ControlToValidate = "txtPointValue";
                            rv.Display = ValidatorDisplay.Dynamic;
                            rv.ErrorMessage = "Please select a value";
                            rv.CssClass = "validator";
                            rv.ValidationGroup = "CallID";
                            rv.InitialValue = "";
                            e.Item.Controls[3].Controls.Add(rv);

                           TextBox txt = new TextBox();
                            txt.ID = "txtPointValue";
                            txt.Width = 100;
                            e.Item.Controls[3].Controls.Add(txt);

                    TextBox txtNotes = new TextBox();
                    txtNotes.ID = "txtNotes";
                    txtNotes.TextMode = TextBoxMode.MultiLine;
                    txtNotes.Width = 250;
                    e.Item.Controls[4].Controls.Add(txtNotes);

                    CheckBox chkbxNotApplicable = new CheckBox();
                    chkbxNotApplicable.ID = "chkbxNotApplicable";
                    chkbxNotApplicable.Text = "Not Applicable";
                    chkbxNotApplicable.AutoPostBack = true;
                    chkbxNotApplicable.CheckedChanged += new EventHandler
                        (chkbxNotApplicable_CheckedChanged);
                    
                    e.Item.Controls[5].Controls.Add(chkbxNotApplicable);

                }
            }
--------------------------------------------------------------------------------------------------------------------------------------
The check box has "_CheckedChanged" event that do what I want server side.
---------------------------------------------------------------------------------------------------------------------------------------
 protected void chkbxNotApplicable_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkbxNotApplicable = (CheckBox)sender;
            GridDataItem item = (GridDataItem)((GridTableCell)chkbxNotApplicable.Parent).Parent;
            RequiredFieldValidator validator = ((RequiredFieldValidator)((Control)item["Pointvalue"].Controls[0]));
            validator.Enabled = !chkbxNotApplicable.Checked;
        }
---------------------------------------------------------------------------------------------------------------------------------------
I want to access the "RequiredFieldValidator4" javascript and disable it if the user check the chkbxNotApplicable checkbox.
I mean, I want to do the same job of the chkbxNotApplicable checkbox using javascript not a server side code.

Is it possible?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Oct 2011, 08:58 AM
Hello Mohamed,

You can try the following code library approach to access the control in Template column.
Accessing server controls in a grid template on the client.

Thanks,
Shinu.
0
Mohamed
Top achievements
Rank 2
answered on 03 Oct 2011, 11:56 AM
Thank you for replying,
The problem is that I'm creating the controls at runtime when the client id is not yet available.
Also I need to access the controls in the detailed grid not the main grid
0
Mohamed
Top achievements
Rank 2
answered on 05 Oct 2011, 08:26 AM
Thank you, I found a solution by passing the validator from the code behind to javascript function, and it's working good.

Thanks
Tags
Grid
Asked by
Mohamed
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Mohamed
Top achievements
Rank 2
Share this question
or