1
Answer

How to call javascript written in aspx from code behind?

Photo of Amol

Amol

13y
1.2k
1

Here is the scenario i have to call javascript from server side
is it possible then please suggest

<html xmlns="http://www.w3.org/1999/xhtml">     <head runat="server"> <title>Untitled Page</title> <script type="text/javascript">     function test(x, y)     {       } </script> </head> <body>     <form id="form1" runat="server">     <div>         <asp:Button ID="Button1" runat="server" Text="Button"          onclick="Button1_Click"/>     </div>     </form> </body> </html>


protected void Button1_Click(object sender, EventArgs e) {     // do stuff (really going to a database to fill x and y) 
// call javascript function as test(x,y);  }

Answers (1)

0
Photo of Carlos Sanchez
NA 264 0 20y
Thank you jshepler. I prefer the first method, cuz is esier and cuz I dont know if the second method is possible in C#. thank you again, I appreciate your help. Regards.
0
Photo of jshepler
NA 63 0 20y
2 ways to do this: 1. Combine the two (or more) columns in your select statement: SELECT IDEmploee, Name + ' ' + LastName + ' ' + SecondLastName AS 'Employee'. You would then have 2 columns: IDEmployee and Employee. 2. Tell the datagrid not to automatically generate the columns - do them manually: Employee <%# DataBinder.Eval(Container.Dataitem, "Name") %> <%# DataBinder.Eval(Container.Dataitem, "LastName") %> <%# DataBinder.Eval(Container.Dataitem, "SecondLastName") %> The first method is the preferred way unless you need to have the columns seperate for something else. Having the database doing the work is much more efficient, not to mention easier to code.