Click here to Skip to main content
15,671,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Masked edit extender in my gridview. I am displaying this gridview dynamically based on types, If the type is "T" it displays only textbox, if the type is "DT" it displays textbox with calendar.

I am using the same textbox, and in grid row databound event, I am hiding and showing the calendar button. But if I give the maskededitextender in the gridview, the mask is being applied for the nondate fields also.

I tried by giving a dummy textbox and make it as targetcontrolid for the maskededtextender and in rowdatabound event, I am setting the targetcontrolid of the maskededitextender to my textbox if the type is date. But it is not working.

can anyone please help me on this?

What I have tried:

Below is the rowdatabound event code:

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
MaskedEditExtender ME = (MaskedEditExtender)e.Row.FindControl("MaskedEditExtender1");
TextBox txtValue1 = (TextBox)e.Row.FindControl("txtValue1");
TextBox txttest = (TextBox)e.Row.FindControl("txttest");
HiddenField hfInputType = (HiddenField)e.Row.FindControl("hfInputType");
ImageButton imgBtnFromDate = (ImageButton)e.Row.FindControl("imgBtnFromDate");
ME.TargetControlID = txttest.ClientID;
txtValue1.Style.Add(HtmlTextWriterStyle.Display, "block");
imgBtnFromDate.Style.Add(HtmlTextWriterStyle.Display, "block");
ME.TargetControlID = txtValue1.ClientID;
else if(hfInputType.Value=="U")
txtValue1.Style.Add(HtmlTextWriterStyle.Display, "block");
imgBtnFromDate.Style.Add(HtmlTextWriterStyle.Display, "none");
} code:

<asp:ImageButton ID="imgBtnFromDate" runat="server" Style="display: none" ImageUrl="~/App_Themes/Black/Images/Calendar.png" />
<cc1:CalendarExtender ID="ceFromDate" PopupButtonID="imgBtnFromDate" runat="server"

<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" AcceptNegative="Left"
DisplayMoney="Left" Mask="99/99/9999" MaskType="Date" MessageValidatorTip="true"
Updated 19-Aug-16 19:47pm

1 solution

remove this line
ImageButton imgBtnFromDate = (ImageButton)e.Row.FindControl("imgBtnFromDate"); 
ME.TargetControlID = txttest.ClientID; // this is global scope, it will be applied to all controls. 
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900