Hi,
How to use javasript call a method with parameters?
Codes:
WebForm1.aspx:
function Test() {
// Call 'CheckValid(string[] values)' and passing parameters to it?
}
WebForm1.aspx.cs:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack) {}}
public void CheckValid(string[] values) {// etc...}
}
}
Thanks.


Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 13, 2014, 3:25 AM EDT
Can you please explain more where you want to call the javascript method
for ex. any textbox validation or dropdown change event.
Ken HRank #2,315 · 610 reputationPosted Apr 14, 2014, 6:17 AM EDT
I need to trigger the client control's 'onclick' event.
Thank you.
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 15, 2014, 12:29 AM EDT
if you want on click event you need to register you javascript method first.
for example
Private voit javascriptmethod(){
if (chkTillDate.Attributes["OnClick"] == null)
chkTillDate.Attributes.Add("OnClick", "return disableDateDropDowns(this,getElementById('" + txtToDay.ClientID + "'),getElementById('" + txtToMonth.ClientID + "'),getElementById('" + txtToYear.ClientID + "'));");
else
chkTillDate.Attributes["OnClick"] = "return disableDateDropDowns(this,getElementById('" + txtToDay.ClientID + "'),getElementById('" + txtToMonth.ClientID + "'),getElementById('" + txtToYear.ClientID + "'));";
}
and after in aspx page
function disableDateDropDowns(chk, ddlDay, ddlMonth, ddlYear) {
if (chk.checked == true) {
ddlDay.disabled = true;
ddlMonth.disabled = true;
ddlYear.disabled = true;
ddlDay.innerText = "";
ddlMonth.innerText = ""
ddlYear.innerText = "";
}
else {
ddlDay.disabled = false;
ddlMonth.disabled = false;
ddlYear.disabled = false;
}
Ken HRank #2,315 · 610 reputationPosted Apr 25, 2014, 5:41 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted May 6, 2014, 4:39 AM EDT
what error u are getting.