Hello there!,
I have text boxes, drop down list boxes in my web page (C#) .
i am passing the client id of the controls to one jscript
that is
txtcode.Attributes.Add("OnChange", "return Validation(\'" + (txtcode.ClientID + "\',\'Code\');"));
txtphone.Attributes.Add("OnChange", "return Validation(\'" + (txtphone.ClientID + "\',\phone number\');"));
txtname.Attributes.Add("OnChange", "return Validation(\'" + (txtname.ClientID + "\',\'Name\');"));
txtCity.Attributes.Add("OnChange", "return Validation(\'" + (txtCity.ClientID + "\',\'City Code\');"));
txtState.Attributes.Add("OnChange", "return Validation(\'" + (txtState.ClientID + "\',\'State Code\');"));
so i am here passing the client id of the control and i will catch the those in the jscript like
function Validation(ctrl,type)
{
var str = document.getElementById(ctrl).value;
if (str.length<1||!str.match(/[^\s]/))
{
alert("Please Enter"+" "+type);
document.getElementById (ctrl).focus();
document.getElementById (ctrl).value="";
return false;
}
return true;
}
i am just validating those controls when only there text changes.
consider when i want to validate those text boxes when the submit button is clicked, then how can i pass all their ids in to one function which executes when the submit button is clicked
that is
like
btnSubmit.Attributes.Add("OnClick", "return whole(\"'some values"')");
Could you please tell me a solution?
Praveen VenugopalPosted Aug 23, 2008, 12:01 AM
the Answer is
protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TextBox t1 = (TextBox)(e.Item.Cells[4].FindControl("Act_Sdate"));
t1.Attributes.Add("OnChange", "return DateValidation('" + t1.ClientID + "','Actual Start Date');");
TextBox t2 = (TextBox)(e.Item.Cells[5].FindControl("Act_Edate"));
t2.Attributes.Add("OnChange", "return DateValidation('" + t2.ClientID + "','Actual End Date');");
TextBox t3 = (TextBox)(e.Item.Cells[6].FindControl("Perc_comp"));
t3.Attributes.Add("OnChange", "return FloatValidation('" + t3.ClientID + "','Percentage of Completion');");
btnSave.Attributes.Add("OnClick", "return whole('"+ t1.ClientID + "','Start Time','" + t2.ClientID + "','End Time','" + t3.ClientID + "','Percentage Of Completion');");
}
}
catch (Exception ex)
{
Session["Error"] = ex;Response.Redirect("../Error_Page.aspx");
Response.Close();
}
}
DanPosted Aug 22, 2008, 1:57 PM
System.Web.UI.WebControls.
RegularExpressionValidator