Register JavaScript before <form> tag

Is it possible to register a JavaScript before the <form> tag.

RegisterStartupScript registers it just before the closing tag </form> and RegisterClientScriptBlock registers it just after the opening tag <form>. I would like to register it before the open <form> tag
0
andrew_bourne
10/11/2003 11:09:45 AM
asp.net.client-side 24353 articles. 2 followers. Follow

2 Replies
1149 Views

Similar Articles

[PageSpeed] 52
Get it on Google Play
Get it on Apple App Store

can you describe what you're trying to accomplish?  you can probably re-tool your processing to fit one of the given methods.
0
hlaford
10/11/2003 5:53:15 PM


There are a few ways to do this. One way is to place an <asp:Literal> control on your page before your open <form> tag and give it an id. From page_load, or some other event hander, populate the Text property:

<asp:Literal id="myScript" runat="server"></asp:Literal>
<form runat="server">
<p>

void Page_Load(Object sender, EventArgs e) {
System.Text.StringBuilder mySB = new System.Text.StringBuilder();
mySB.Append("<script language=\"javascript\">");
mySB.Append("alert('Test');");
mySB.Append("</" + "script>");

myScript.Text = mySB.ToString();
}

I used a StringBuilder to build the string mainly because I like the syntax; they are also more efficient at string concatenation. You could do this just as easily with a String variable. The closing </script> tag is broken into two pieces, otherwise it won't work. This code wouldn't be much differnt in VB.

Jamie Kindred, CGA, MCSD
0
NetProfit
10/11/2003 11:00:02 PM
Reply:

Similar Artilces:

How to strip a string of <html>, ,</html>, <body>, </body>, <form ... >, </form> tags?
I have stream which is the HTML input of a page. Now I want to use only that part of this page, that is within <form .....> and </form> tags, and excluding these tags.How would I go about stripping <html>, ,</html>, <body>, </body>, <form ... >, </form>, <head> and </head> tags? I have to make sure that <head ...javascript..> and its corresponding </head> tags are not stripped in this process.sun21170    Wait... you said you wanted to strip the head tags, and you're also saying you need to NOT strip the ...

<<<< Caling sever side function inside Javascript function >>>
i wont to call server side function inside a javascript functionex:-.cs file protected void add(){//................................ }  .aspx file  <script>function ClientsideAdd(){///  I wont to call the sever side function  'add()'  hear} </script>   Any one knows how to do this.....Thank You  You'll probably get a bunch of replies saying "You can't do that, server side scripts run on the server, client side scripts run on the client, and they happen seperately and at seperate times&qu...

Need Help With <form runat=server></form> Tags
Hello everyone I have a real newbie question for anyone that wants to help me out...... I am creating a e-commerce website right now (yes a massive project for me) and I am having this problem. I have set up my site with a master page and then the content pages. On my master page I have a login view and inside that login view I have a login name <asp:LoginName ID="LoginName1" runat="server"> I just draged and dropped it so when my users are signed in they can see a welcome message... this login name requires a <form runat=server> Tag in which I've placed in it....(this works ...

Firefox issue with dynamic height inside <form></form> tags
Maybe someone else has experienced this and has a work around.I have a site with a master page that has an iFrame the I load a dynamic URL into, all code works fine. In IE I have no problems but in firefox if the iFrame with the height as a % does NOT resize to the right height if the iframe is inside the <form></form> tags.I've copied the rendered html and put it in a plain html page and when I remove the form tags I have no problems. Has anyone encountered this?Below is my posted .aspx code I've put the style inline in the iFrame for ease of viewing, before it was in a ...

Is it possible to run custom controls in <title><meta> tags without placing the form tag at the start of the page?
Hi, I have created a group of custom controls to allow users/designers to edit the design of dynamic pages easily without doing any code, basically they get given the custom controls and can drop them into web pages and it pulls up the appropriate information when ran on my server (from the querystring/public properties etc), sounds great so far. But my problem is that I want them to be able to put the tags into other parts of the page outside of the body tag, including the pages metadata/title etc eg <title><mytag:pagename runat="server"></title> ...

Can't use "defaultbutton" in <form></form> tag in login control page.
I have a login control and I tried to set the default button as the submit button within my form tag in the login page.But, I am getting the following error.Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. I already generated the machine key.Any clue! hi robin, Please try this fix if.. add the below given code into your web.config or the file that you are executing and see if your issue gets...

Adding run-time created <li></li> tags inbetween <ul>/ul> tags
I want to create a custom control which will create a unordered list and fill it with list items of which will be created at run-time. Currently I am using the following logic: At my Default.aspx page:<ai:ul_adder ID="ul_adder1" ListItemString="Page1 1,sf1.aspx,image/edit.gif; Page 2,sf2.aspx,image/colaps.gif" runat="server"/>and at the ul_adder.ascx file 1 public string ListItemString 2 { 3 set 4 { 5 string[] itemlist = value.Split(';'); 6 7 for (int i = 0; i < itemlist.Length; i++) 8 ...

Bug rendering <p> tags around <pre> or <code> tags
Name: Tim Robinson Email: tcr1272atgmaildotcom Product: Firefox Summary: Bug rendering <p> tags around <pre> or <code> tags Comments: Two Examples below, both render the <p> tags differently and incorrectly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <p> <pre> <div> my text </div> </pre> <p> <body> <html> <!DOCTYP...

this in vb.net: <% using Html.Form<ProductController>(p=>p.Update(ViewData.Product.ProductID))%>
How do I do this in VB.net:<% using Html.Form<ProductController>(p=>p.Update(ViewData.Produc t.ProductID))%>This is using a lambda for the form tag in c#, I searched everywhere for the correct vb.net syntax? I tried this with no luck:<% Using Html.Form(Of ProductController)(Function(p) p = ViewData.Product.ProductID)%>   VB.NET doesn't support Lambda expressions.   View My Blog Download My URL Rewriter and Reverse ProxyOnly $9.95/month, ASP.NET, 2GB & SQL 2005 alivemedia:Function(p) p = ViewData.Product.ProductID I think the proper syn...

register a client side script on the form tag
I need to add some JS to the onsubmit attribute of the form tag in an aspx page. I know how to do it for lets say a button cmdMyButton.Attributes("onclick") = whatever... or cmdMyButton.Attributes.Add("onclick","whatever") but i need to add it to the form tag, which isn't available server side i guess??? but since all aspx pages have a form, there should be a server side reference to it right? You can, in fact must (if you're using WebControls that require PostBack), include runat="server" in a <form>. All you need to do is add an id attribute and then do the same as y...

Inline tags...<%=%>, <%# %>, <%$ %> ....etc...
I come from a classic ASP background, so I know what <%= [string] %> means...but what about:  <%# expression %> and <%$ expression %>  --------------- I've seen <%# expression %> used mainly in databinding (<%# Bind("employeename") %>) for a TemplateField but am not sure exactly what it means (though I know what it does). I would think that <%= and <%# are synonymous but it seems they are not. <%$ expression %> I've only seen in an SqlDataSource when setting the ConnectionString attribute to: <%$ ConnectionStri...

Lists in .net
Like a good AKA accessible app building developer, my application's navbar is controlled with CSS and using <ul> and <li> I just have the code in the HTML display and it works fine when everything should be visible, however, I need to restrict some users from viewing certain navbar links based on their security levels.  How do I hide the list items that need to be hidden? TIA hello! give them ids and runat="server" attribute. then in code behind set the Visible property to false. orzeh code less, think more! Okay, I tried putting the link as a link bu...

Inserting <Object> before <form> tag when rendering control
I have an ActiveX object that must be delcared outside the default <form> tag of my web control. In other words, when the control renders and writes out the <form element>, I need to place an object tag BEFORE "<form>" is written. What happens now: <form VIEWSTATE= " ... " > <object> objectstuff </object> </form> what I need is: <object>objectstuff</object> <form VIEWSTATE= " ... " ></form> I have tried the RegisterClientScriptBlock method on a whim, but it places ...

How to remove <p> and <b> and <i> tags
Hi, I have some text in the database which has Html tags. I want that when I display the data the tags are removed.HighOnCodingWanna get high! You might consider called Server.HtmlEncode(data) on the rows to convert the html to characters that will be displayed in the browser.--Brian DesmondWindows Server MVP - Directory Serviceshttp://www.briandesmond.com Hi, Thanks for the Quick reply. Well now its displaying something like this: " &lt;P&gt;&lt;P&gt; &lt;i&gt;&lt;P&gt;if( dr.Read())&lt;P&gt;&lt;P&gt;{&lt;P&am...

Web resources about - Register JavaScript before <form> tag - asp.net.client-side

Resources last updated: 12/17/2015 5:55:55 PM