admin管理员组文章数量:1355694
I'm working on asp (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
I'm working on asp (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
Share Improve this question edited Apr 18, 2014 at 3:31 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Jul 21, 2011 at 11:55 IrfanIrfan 5,07212 gold badges54 silver badges63 bronze badges 2- What exactly are you trying to acplish? – Shaun Mason Commented Jul 21, 2011 at 12:21
- possible duplicate of How to call JavaScript/jQuery function from .cs file C# – Jason Aller Commented Apr 20, 2014 at 14:35
3 Answers
Reset to default 3you can try to write to a response stream directly and output
Response.Write("<script type=\"text/javascript\"> your JS call</script>");
Regards, Szymon
You can call a JavaScript function using registerStartupScript
.
ASPX Page
<script type="text/javascript">
function printOutput(arg) {
alert(arg);
}
</script>
Code Behind
protected void DoSomethingButton_Click(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(typeof (Page), "PrintScript_" + UniqueID, "printOutput('My HTML Code Generated by jquery function');", true);
}
You need to pass into the web.cs a reference to the page. You will then have access to the page.clientscript method
本文标签:
版权声明:本文标题:How to call JavaScriptjQuery function from .cs file (C#) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743960504a2568936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论