How can i call C# function Through javascript on aspx page
-
Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam
-
Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam
-
Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam
AJAX[^] is the answer. To make things easier, use AJAX toolkit for ASP.NET. :)
Navaneeth How to use google | Ask smart questions
-
I already have my function on mypage.aspx.cs page. I want to call this on aspx page. so how can i do this
-
AJAX[^] is the answer. To make things easier, use AJAX toolkit for ASP.NET. :)
Navaneeth How to use google | Ask smart questions
i'm not much aware about Ajax.Could you tellme the any other.I have my function in aspx.cs page I call this on aspx page
-
i'm not much aware about Ajax.Could you tellme the any other.I have my function in aspx.cs page I call this on aspx page
-
Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam
I would prefer you to use AJAX but here is one other solution. From javascript make a call to dopostback method with eventtarget and arguments (if reuqired) and in Page Load method check for the event target and call the C# method. Remember this is dirty trick. JavaScript (JS File)
__doPostBack('CALL_MY_METHID','');
ASPX Code Behind
void Page_Load(object sender, EventArgs e)
{
....
....// Insure that the __doPostBack() JavaScript method is created...
this.GetPostBackEventReference(this, string.Empty);string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
if (eventTarget == "CALL_MY_METHID")
{
// Call your C# method here and return
CallMyMethod();
return;
}
....
....
}Be careful, there is no Undo Button(Ctrl+Z) in life.
-
I would prefer you to use AJAX but here is one other solution. From javascript make a call to dopostback method with eventtarget and arguments (if reuqired) and in Page Load method check for the event target and call the C# method. Remember this is dirty trick. JavaScript (JS File)
__doPostBack('CALL_MY_METHID','');
ASPX Code Behind
void Page_Load(object sender, EventArgs e)
{
....
....// Insure that the __doPostBack() JavaScript method is created...
this.GetPostBackEventReference(this, string.Empty);string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
if (eventTarget == "CALL_MY_METHID")
{
// Call your C# method here and return
CallMyMethod();
return;
}
....
....
}Be careful, there is no Undo Button(Ctrl+Z) in life.
.NET is parsed by the server. Javascript is parsed by the browser. If you have page that is already loaded that you want to process a .NET page, asking the server to do so via Javascript is the best way. Ranjit Viswakumar Professional Services Specialist HostMySite.com[^]