Validate User Input before calling java script function

S

Santosh

Hii i am writting a code for adding a user records but i want to
activate required filed validator before displaying conform addition
messagebox

i am writtng following code but it is never work please tell me that
what is solution behind them.


public void SetUpClientValidation(object sender, DataGridItemEventArgs
e)
{
if ( e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.SelectedItem )
{
e.Item.Cells[4].Attributes.Add("OnClick","JavaScript:return
ConfirmDeletionInformation();");
}
if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[3].Attributes.Add("OnClick","JavaScript:return
ConformAddInformation();");

}


//
public void DataGridItemCommand(object sender, DataGridCommandEventArgs
e)
{
try
{
switch(e.CommandName)
{
case "GotoDistrict":
GoToDistrict(e.Item,e.Item.ItemIndex);
break;
case "AddNewRecords":
AddNewRecords(e.Item,e.Item.ItemIndex);
break;
}
}
catch(Exception ex)
{
ex.Message.ToString();
}
}


//

private void AddNewRecords(DataGridItem item, int rowIndex)
{
try
{
RequiredFieldValidator stateNoRequired
=(RequiredFieldValidator)item.FindControl("stateNo_Requiredfieldvalidator");
RequiredFieldValidator stateDescRequired
=(RequiredFieldValidator)item.FindControl("stateDesc_Requiredfieldvalidator");
RangeValidator stateNoRange =
(RangeValidator)item.FindControl("stateNo_RangeValidator");
stateNoRequired.Enabled = true;
stateDescRequired.Enabled = true;
stateNoRange.Enabled = true;

TextBox stateNo_TextBox =
(TextBox)item.FindControl("addStateNo_TextBox");
TextBox stateName_TextBox =
(TextBox)item.FindControl("addStateDesc_TextBox");

string recordFound =objStateMaster.FindRec(stateNo_TextBox.Text
,stateName_TextBox.Text);

if (recordFound!="")
{
string msg = " already exists" ;
string space = " and ";
string stateNo="StateNo: ";
string stateDesc= "StateName: ";


switch(recordFound)
{
case "11":
Response.Write("<script language=javascript> alert('"+ stateNo +
"' +'" + stateNo +"' + '"+ space +"' + '"+ stateDesc +"' + '"+
stateDesc +"'+ '" + msg + "');</script>");
break;
case "10":
Response.Write("<script language=javascript> alert('"+ stateNo
+"' +'" + stateNo +"' + '" + msg + "');</script>");
break;
case "01":
Response.Write("<script language=javascript> alert('"+ stateDesc
+"' +'"+ stateDesc + "' + '" + msg + "');</script>");
break;
}
return;
}

if(stateNo_TextBox != null)
{
objStateMaster.StateNo = stateNo_TextBox.Text;

}

if(stateName_TextBox != null)
{
objStateMaster.StateDesc = stateName_TextBox.Text;
}

objStateMaster.AddRec();
BindDataGrid();
stateNo_TextBox.Text="";
stateName_TextBox.Text="";

stateMaster_DataGrid.Columns[5].Visible = true;
}
catch(Exception ex)
{
ex.Message.ToString();
}
}

Regards,
Santosh Shinde
Vritti Software Solution.
 
S

Scott M.

Why not just use the RequiredFieldValidator controls and let them do all the
work?


Santosh said:
Hii i am writting a code for adding a user records but i want to
activate required filed validator before displaying conform addition
messagebox

i am writtng following code but it is never work please tell me that
what is solution behind them.


public void SetUpClientValidation(object sender, DataGridItemEventArgs
e)
{
if ( e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.SelectedItem )
{
e.Item.Cells[4].Attributes.Add("OnClick","JavaScript:return
ConfirmDeletionInformation();");
}
if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[3].Attributes.Add("OnClick","JavaScript:return
ConformAddInformation();");

}


//
public void DataGridItemCommand(object sender, DataGridCommandEventArgs
e)
{
try
{
switch(e.CommandName)
{
case "GotoDistrict":
GoToDistrict(e.Item,e.Item.ItemIndex);
break;
case "AddNewRecords":
AddNewRecords(e.Item,e.Item.ItemIndex);
break;
}
}
catch(Exception ex)
{
ex.Message.ToString();
}
}


//

private void AddNewRecords(DataGridItem item, int rowIndex)
{
try
{
RequiredFieldValidator stateNoRequired
=(RequiredFieldValidator)item.FindControl("stateNo_Requiredfieldvalidator");
RequiredFieldValidator stateDescRequired
=(RequiredFieldValidator)item.FindControl("stateDesc_Requiredfieldvalidator");
RangeValidator stateNoRange =
(RangeValidator)item.FindControl("stateNo_RangeValidator");
stateNoRequired.Enabled = true;
stateDescRequired.Enabled = true;
stateNoRange.Enabled = true;

TextBox stateNo_TextBox =
(TextBox)item.FindControl("addStateNo_TextBox");
TextBox stateName_TextBox =
(TextBox)item.FindControl("addStateDesc_TextBox");

string recordFound =objStateMaster.FindRec(stateNo_TextBox.Text
,stateName_TextBox.Text);

if (recordFound!="")
{
string msg = " already exists" ;
string space = " and ";
string stateNo="StateNo: ";
string stateDesc= "StateName: ";


switch(recordFound)
{
case "11":
Response.Write("<script language=javascript> alert('"+ stateNo +
"' +'" + stateNo +"' + '"+ space +"' + '"+ stateDesc +"' + '"+
stateDesc +"'+ '" + msg + "');</script>");
break;
case "10":
Response.Write("<script language=javascript> alert('"+ stateNo
+"' +'" + stateNo +"' + '" + msg + "');</script>");
break;
case "01":
Response.Write("<script language=javascript> alert('"+ stateDesc
+"' +'"+ stateDesc + "' + '" + msg + "');</script>");
break;
}
return;
}

if(stateNo_TextBox != null)
{
objStateMaster.StateNo = stateNo_TextBox.Text;

}

if(stateName_TextBox != null)
{
objStateMaster.StateDesc = stateName_TextBox.Text;
}

objStateMaster.AddRec();
BindDataGrid();
stateNo_TextBox.Text="";
stateName_TextBox.Text="";

stateMaster_DataGrid.Columns[5].Visible = true;
}
catch(Exception ex)
{
ex.Message.ToString();
}
}

Regards,
Santosh Shinde
Vritti Software Solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top