2
Answers

How to pass client id of multiple controls to one jscript function

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?

Answers (2)

0
Photo of Christian
NA 24 0 15y

Its not the sql query im confused about its more about how the easiest way is to work with a datetime in C# and in sql. I need to have the dates displayed on my webpage but I also need to use the dates for sorting in my sql queries. I coul dsave the datetime as a string in db so it would be easy to retreive it and display it but im just not sure if I would be able to sort with it since its a string in my db. Then I need to save it as a timestamp in the db but I just want to make sure that sql timestamp is easy to work with and easy to convert into string when i want it in my c# code.
0
Photo of Lalit M
NA 6.7k 48k 15y
try this code retreive rows sorted by datetime

SELECT orderID, DATEPART(MM,OrderDate) AS OrderMonth FROM Orders

more info

http://www.sqlmag.com/article/articleid/43488/43488.html
0
Photo of Amit Choudhary
NA 27.7k 3m 15y
hi friend,

Simply using DateTime data type in sqlserver can solve your problem.


Please mark the anser if it helps.