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

Obtaining values of controls within a EditTemplate when utilizing the OnCheckedChanged method

0 Answers 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vzzak
Top achievements
Rank 1
vzzak asked on 09 Jul 2008, 03:33 PM

I was struggling with this issue of trying to reference controls within the same Edit Template, when using the OnCheckChanged method of the Checkbox in the template.  See the solution below. Hope this saves someone some time and effort.

Obtaining values of controls within a EditTemplate when utilizing the OnCheckedChanged method of a checkbox control in the same Template.

This uses a Server Side event. 

protected

void CheckedChanged(object sender, System.EventArgs e)

{

CheckBox chkBox = (sender as CheckBox);

GridDataItem item = (GridDataItem)chkBox.NamingContainer;

RequiredFieldValidator reqval = (RequiredFieldValidator)item["EndDateTime"].FindControl("reqEndDate");

RegularExpressionValidator regexval = (RegularExpressionValidator)item["EndDateTime"].FindControl("regexEndDate");

if (chkBox.Checked)

{

reqval.Enabled =

false;

regexval.Enabled =

false;

}

}

Here is the ASPX

<EditItemTemplate>

<asp:TextBox ID="EndDateTimeTextBox" runat="server" ></asp:TextBox><asp:RequiredFieldValidator

ID="reqEndDate" runat="server" ControlToValidate="EndDateTimeTextBox" ErrorMessage="A valid US Date & Time is Required."

Style="left: 2px; position: relative">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator

ID="regexEndDate" runat="server" ControlToValidate="EndDateTimeTextBox" ErrorMessage="Please enter a valid US Date & Time."

Style="position: relative" ValidationExpression="^(([1-9])|(0[1-9])|(1[0-2]))\/(([0-9])|([0-2][0-9])|(3[0-1]))\/(([0-9][0-9])|([1-2][0,9][0-9][0-9]))\s(1[0-2]|[1-9])\:[0-5][0-9]\s(a|p|A|P)(m|M)$">*</asp:RegularExpressionValidator>

<br />

<asp:CheckBox ID="chkIsFullDay" runat="server" Style="position: relative" Text="Full Day" AutoPostBack="True" OnCheckedChanged="CheckedChanged" />

</EditItemTemplate>

No answers yet. Maybe you can help?

Tags
Grid
Asked by
vzzak
Top achievements
Rank 1
Share this question
or