Click here to Skip to main content
15,910,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating the new row inside the grid view from external button present outside the grid view with dynamically creating the dropdownlist and validating it. It used to work fine until I have moved the grid view inside the update panel.

Is there any way to validate the dropdownlist inside the UpdatePanel?

Here's my code so far:

C#
DropDownList ddlEmployeeName1 = new DropDownList();

ddlEmployeeName1.ID = "ddlEmployeeName1";
ddlEmployeeName1.Attributes.Add("runat", "server");
ddlEmployeeName1.Width = 200;
ddlEmployeeName1.ValidationGroup = "valSave";
ddlEmployeeName1.CausesValidation = true;
DropDownList ddlEmployeeRole = new DropDownList();
ddlEmployeeRole.ID = "ddlEmployeeRole";

ddlEmployeeRole.Attributes.Add("runat", "server");

if (!generic.isRowDataSaved)
{
    // e.Row.Cells[1].Controls.Add(lblEmployeeCode);
    e.Row.Cells[2].Controls.Add(ddlEmployeeName1);
    e.Row.Cells[3].Controls.Add(ddlEmployeeRole);   //textbox is added as last column of grid
    List<employeebo> employeeList = new List<employeebo>();
    EmployeeService employeeService = new EmployeeService(this.ContextBO);

    lblPoNumberIns1.Text = "PO12345";
    ddlEmployeeName1.EnableViewState = true;
    ddlEmployeeName1.AppendDataBoundItems = true;
    ddlEmployeeName1.AutoPostBack = true;
    employeeList = employeeService.GetEmployeeList();//(List<employeebo>)Session[UIConstants.GetEmployeeList];
    ddlEmployeeName1.DataSource = employeeList;
    ddlEmployeeName1.Items.Add(new ListItem("Please Select EmployeeName", "0"));
    ddlEmployeeName1.Font.Size = FontUnit.XXSmall;
    ddlEmployeeName1.Width = 200;
    ddlEmployeeName1.CausesValidation = true;
    ddlEmployeeName1.DataTextField = "EmployeeName";
    ddlEmployeeName1.DataValueField = "EmployeeOrbitCode";
    ddlEmployeeName1.DataBind();
    ddlEmployeeName1.Attributes.Add("onChange", "return empOrbitCodeUpd(this," + e.Row.RowIndex + ");");
    RequiredFieldValidator nameValidator = new RequiredFieldValidator();
    if (ddlEmployeeName1.SelectedValue.ToString() == "0")
    {
        nameValidator.ControlToValidate = ddlEmployeeName1.UniqueID;
        nameValidator.Attributes.Add("runat", "server");

        nameValidator.ErrorMessage = "Please Select EmployeeName";
        nameValidator.Font.Size = FontUnit.XXSmall;
        nameValidator.ID = "nameValidator";
        nameValidator.Display = ValidatorDisplay.Dynamic;
        nameValidator.SetFocusOnError = true;
        nameValidator.ValidationGroup = "valSave";
        nameValidator.InitialValue = "0";
        nameValidator.Text = "*";

        this.Form.Controls.Add(nameValidator);
     }
Posted
Updated 6-Oct-14 0:36am
v2
Comments
Kornfeld Eliyahu Peter 6-Oct-14 6:45am    
If I understand your question right, you are validating on server side...Controls inside UpdatePanel will be excluded from postback if you do not declare UpdatePanel properties well...
santoshkumar413 6-Oct-14 6:56am    
@Kornfeld, Thank u for the reply, yeah i am trying to validate on server side, can u gice sample code where i can declare the updatepanel

1 solution

use the <scriptmanager> tag outside the <updatepanel> tag
 
Share this answer
 
Comments
santoshkumar413 6-Oct-14 7:01am    
@MukeshSagar, Thanks for the reply, can please elaborate your answer, where i can add the scriptmanager, i have already added the tooscript manager inside the master page.
MukeshSagar 6-Oct-14 7:21am    
Before the UpdatePanel tag
santoshkumar413 6-Oct-14 8:19am    
@Mukesh, I have added the script manager, but still validation doesnot works.
MukeshSagar 6-Oct-14 8:27am    
Then send the code for aspx file and .cs file, then only i can check for the problem
santoshkumar413 6-Oct-14 8:31am    
GridView Row DataBound
protected void grdProjectEmpUpdDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
// if (e.Row.RowType == DataControlRowType.Header) return;

EmployeeBillingBO generic = (EmployeeBillingBO)e.Row.DataItem;

DateTime startDateValue = Convert.ToDateTime(ViewState["DtEndDate1"]); //= endDateValue;
DateTime endDateValue = Convert.ToDateTime(ViewState["DtStartDate1"]); //= startDateValue;

List<employeetotalactualeffortsforaperiodbo> listEAEP;
listEAEP = (List<employeetotalactualeffortsforaperiodbo>)Session["eapList"];


#region Created new Row

if (btnAddNewRow.UniqueID == this.GetPostBackControlID() && !string.IsNullOrEmpty(hdnViewList.Value) && e.Row.RowIndex == Convert.ToInt16(hdnViewList.Value))
{
EmployeeBillingService gs = new EmployeeBillingService(this.ContextBO);

for (int i = 0; i < lbxProjectList.Items.Count; i++)
{

if (lbxProjectList.Items[i].Selected.Equals(true))
{

List<employeebillingbo> gList = gs.GetEmployeeProjectDetails(Convert.ToInt32(ddlCustomerList.SelectedValue), Convert.ToInt32(lbxProjectList.Items[i].Value), startDateValue, endDateValue);
Session[UIConstants.GetEmployeeProjectDetails] = gList;
}
}
if (DataControlRowType.DataRow == e.Row.RowType && e.Row.RowState != DataControlRowState.Edit && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
Label lblEmployeeCode = new Label(); //here i m adding a control.
lblEmployeeCode.ID = "lblEmployeeCodeIns1";
lblEmployeeCode.Attributes.Add("runat", "server");

Label lblPoNumberIns1 = new Label(); //here i m adding a control.
lblPoNumberIns1.ID = "lblPoNumberIns1";
lblPoNumberIns1.Attributes.Add("runat", "server");
DropDownList ddlEmployeeName1 = new DropDownList();

ddlEmployeeName1.ID = "ddlEmployeeName1";
ddlEmployeeName1.Attributes.Add("runat", "server");
ddlEmployeeName1.Width = 180;
ddlEmployeeName1.ValidationGroup = "valSave";
ddlEmployeeName1.CausesValidation = true;
DropDownList ddlEmployeeRole = new DropDownList();
ddlEmployeeRole.ID = "ddlEmployeeRole";

ddlEmployeeRole.Attributes.Add("runat", "server");

if (!generic.isRowDataSaved)
{
// e.Row.Cells[1].Controls.Add(lblEmployeeCode);
e.Row.Cells[2].Controls.Add(ddlEmployeeName1);
e.Row.Cells[3].Controls.Add(ddlEmployeeRole); //textbox is added as last column of grid
List<employeebo> employeeList = new List<employeebo>();
EmployeeService employeeService = new EmployeeService(this.ContextBO);

lblPoNumberIns1.Text = "PO12345";
ddlEmployeeName1.EnableViewState = true;
ddlEmployeeName1.AppendDataBoundItems = true;
ddlEmployeeName1.AutoPostBack = true;
employeeList = employeeService.GetEmployeeList();//(List<employeebo>)Session[UIConstants.GetEmployeeList];
ddlEmployeeName1.DataSource = employeeList;
ddlEmployeeName1.Items.Add(new ListItem("Pl

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