admin管理员组文章数量:1314252
I'm looking for a way to get the name of the main HTML form so I can submit it from JavaScript.
The reason I can just set the name of the form is because the JavaScript is on a User Control that could get added to many different sites with different form names.
Thanks.
I'm looking for a way to get the name of the main HTML form so I can submit it from JavaScript.
The reason I can just set the name of the form is because the JavaScript is on a User Control that could get added to many different sites with different form names.
Thanks.
Share Improve this question asked Oct 29, 2008 at 1:09 Ryan SmithRyan Smith 8,33422 gold badges78 silver badges103 bronze badges5 Answers
Reset to default 6I'm not totally sure that this will address what you're asking for, so please ment on it:
In your script, when the User Control renders, you could have this placed in there. So long as script doesn't have a "runat" attribute, you should be good.
<script type="text/javascript">
var formname = '<%=this.Page.Form.Name %>';
</script>
I'm not sure , try "YourUserControl.Page.Form"
But why do you need the form name, are you going to have more than one form on your .aspx page , if not, you can get the whole post back JS code for the control that will do the post back (submit) using "Page.ClientScript.GetPostBackEventReference()" and use it to set the "OnClick" attribute of whatever you will use to submit the page.
you can't have more than one form control with runat="server" on an aspx page, so you cn use document.forms[0]
<script type="text/javascript">
var formname = '<%=this.Page.AppRelativeVirtualPath.Replace(this.Page.AppRelativeTemplateSourceDirectory,"")%>';
</script>
ASP.NET pages can only have one form, so its safe to just do:
document.forms[0].submit();
本文标签: javascriptGet the ASPNET form nameStack Overflow
版权声明:本文标题:javascript - Get the ASP.NET form name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741913633a2404590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论