Avatar of mcrmg
mcrmg

asked on 

calling js from c#

Hi,

I have two questions regarding this topic.

1. I am trying to call a js function from c#, this is my test code, but it is not working
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="test2.aspx.cs" Inherits="_test2" %>


<form runat="server" name="form1">

<SELECT multiple size="7" name="testCategory" > 
			      <option value="volvo">Volvo</option>
                  <option value="saab">Saab</option>
                  <option value="mercedes">Mercedes</option>
                  <option value="audi">Audi</option>
			</SELECT> 
			    			
			    			<asp:Button id="testbtn" runat="server" text="test call" />
			    			
<SELECT  CLASS="AdHoc_Form_RIGHT" multiple size=17 name=mainlist></SELECT> 			    			
			    			</form>
			    			
			    			


        
<SCRIPT>   
    function testfuntion() {
        alert("here");
    }
</script>

Open in new window

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _test2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }

    protected void testbtn_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(GetType(), "javascript", "javascript:testfunction();", true); 
        //scriptManager.RegisterClientScriptBlock(this, GetType(), "hello", "testfunction);", true);
    }

}

Open in new window



2. This is the code I use in classic ASP when calling a js function, Is there a way to use it in .net?  thanks
<INPUT onclick="AddListElements(this.form,this.form.testCategory)" type=button value=">>">

Open in new window

ASP.NET

Avatar of undefined
Last Comment
mcrmg

8/22/2022 - Mon