Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call JavaScript/jQuery function from .cs file (C#)

I'm working on asp.net (C#) project which include some page files (aspx, aspx.cs) and some only (.cs) file. I'm able to access JavaScript/jQuery functions from page files (aspx, aspx.cs) using scriptregister, but my question is how to access the JavaScript/jQuery function from alone (.cs) file. I'm generating some html tags in (.cs) file therefore in need of to call JavaScript/jQuery functions from only (.cs) class.

The file I have are, for example, Default.aspx and Default.aspx.cs and Web.cs (My concern is to call JavaScript/jQuery functions from web.cs)

Actually, What I'm trying to do is to generate some HTML code in Web.cs (Business Object) and while generating HTML code in web.cs I need some other dynamic HTML code generated by jQuery function which output is my concern: var output ="My HTML Code Generated by jQuery function"

Now I need the above jQuery output to merger with Web.cs HTML code generating.

Kindly let me know how can it be possible to call jQuery functions from web.cs and get back the result from jQuery to web.cs in order to merge?

Thanks

like image 905
Irfan Avatar asked Sep 26 '26 09:09

Irfan


1 Answers

you can try to write to a response stream directly and output

Response.Write("<script type=\"text/javascript\"> your JS call</script>");

Regards, Szymon

like image 141
Assassin Avatar answered Sep 28 '26 22:09

Assassin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!