asp.net - Call a function defined in an external javascript function from vb.net code behind (.html not .aspx) -
i have plain .html
page has hiddenfield
, reference external.js
. since implementing using asp.net
, server side execute first. however, need execute function in external.js
before server code execution. solution available having next code:
*in .aspx *
<script src="external.js" type="text/javascript"></script> <asp:scriptmanager id="scriptmanager1" runat="server" enablepagemethods="true" />`
in .aspx.vb
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load seek if not page.ispostback scriptmanager.registerstartupscript(me, me.gettype(), "register", "myfunction();", true) end if grab ex exception msgbox(ex.message) end seek end sub
the code works when using .aspx
page. obviously, cannot utilize asp.net
server controls in plain .html
page. using <asp:scriptmanager>
in .html
page not work. how can same exact thing but in .html
page. should defined in .html page
, how can phone call function code behind, keeping in mind cannot utilize <asp:>
controls.
ok trying have external.js
has function populatehidden()
sets value hiddenfield
.
function populatehidden() { document.getelementbyid('hidden').value = "abcdefg"; }
i have function passdata()
initializes ajax request
server pass value of hidden
code behind (using webmethod). problem want populatehidden()
execute first passdata()
passes abcdefg
(after populatehidden()
executed) code behind store value in database. way running both functions follows.
in .html
<body onload="passdata()">
in code-behind
trying execute populatehidden();
on page_load
since server side executes first.
i borrowed @cleydson's answer:
js
function myfunction() { populatehidden(); passdata(); }
html
<html> <head> <meta charset="utf-8"> <title>document</title> <script src="external.js" type="text/javascript"></script> </head> <body onload="myfunction();"> ... </body>
now you're calling populatehidden()
before passdata()
javascript asp.net vb.net
No comments:
Post a Comment