0
Reply

calling the javascript function from C# code

Ask a question
Vinnie

Vinnie

17y
3.3k
1

Hi,

I hope someone can help me with this. I'm calling the javascript function from the aspx.cs  as
     buttonName.OnClientClick = String.Format("JavaScriptFunctionName('{0}', '{1}','{2}'); return false;" ,   Parameter1, Parameter2, Parameter3);

But I want to add aditional checking on the client click as if two text boxes, where user insert dates, are empty then they will be populated with some value or if user doesn't insert hh:mm then I will put default "dd/mm/yy 00:00". So I've created buttonName_Click and added in apsx:  OnClick="buttonName_Click"

       protected void  buttonName_Click(object sender, EventArgs e)
        {
           if Texboxt1 is empty then select date from database and fill Textbox1

          else if date in Textbox1doesn't have hh:mm then add 00:00 to date in Textbox1
           if Texboxt2 is empty then select date from database and fill Textbox2

         else if date in Textbox2 doesn't have hh:mm then add 00:00 to date in Textbox2


          ? call the JavaScriptFunctionName
}

How can I call JavaScriptFunctionName from buttonName_Click ? I can avoid buttonName_Click if you have some other suggestions, but before calling the JavaScriptFunctionName on button click I have to check and fill textboxes also on button click.

Thanks a lot !