Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Validate User Input before calling java script function

Reply
Thread Tools

Validate User Input before calling java script function

 
 
Santosh
Guest
Posts: n/a
 
      06-03-2006
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("stateDe sc_Requiredfieldvalidator");
RangeValidator stateNoRange =
(RangeValidator)item.FindControl("stateNo_RangeVal idator");
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.

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      06-05-2006
Why not just use the RequiredFieldValidator controls and let them do all the
work?


"Santosh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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("stateDe sc_Requiredfieldvalidator");
> RangeValidator stateNoRange =
> (RangeValidator)item.FindControl("stateNo_RangeVal idator");
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a script requiring user input from another script mzagursk@gmail.com Python 1 02-18-2009 09:18 AM
Perl output Javascript to validate user input phal Perl Misc 12 04-10-2006 10:09 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
How to validate the input field values before leaving the JSP page? Arnold Peters Java 1 10-27-2004 07:04 AM
trouble calling a function to validate form input bbxrider Javascript 2 07-30-2003 06:36 AM



Advertisments