How to put Response.Write("<script language='javascript' type='text/javascript'>") into custom server control

Hello,

In my Page_Load I have the following code:

===== 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Response.Write("<script language='javascript' type='text/javascript'>" & vbCrLf)

Response.Write(

"Function();")

Response.Write(

"</script>")

End Sub

===== 

Because I want to re-use this on every webpage, I want to build a custom server control.

How can I implement this?


Johan Theunissen
MCPD, MCSE, MCTS BizTalk 2006

==============================

Please mark the most helpful reply/replies as "Answer".
0
JohanNL
2/13/2007 12:28:37 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

2 Replies
937 Views

Similar Articles

[PageSpeed] 8

Why don't yuo create a Base class that inherits from Page class and make all your pages' code behind classes inherit from that class? Then you place the above code inside the Page_Load of the Base Class?

Check this article to see how to create Base Pages: Using a Custom base Class for your ASP.NET Code behind classes

 

Regards


Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
2/13/2007 12:45:50 PM

Thanx Haidar,

That is exactly what I will do :-)

 


Johan Theunissen
MCPD, MCSE, MCTS BizTalk 2006

==============================

Please mark the most helpful reply/replies as "Answer".
0
JohanNL
2/13/2007 1:03:44 PM
Reply:

Similar Artilces:

When I use Response.Write("<script type='text/javascript' language='javascript'>window.close();</script>"); it produces error
Hi, When I use command below in my web application  it produces error. How can I solve this problem? Thanks.Response.Write("<script type='text/javascript' language='javascript'>window.close();</script>");   Error:  Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.Details: Error parsing near &#...

Can I pass a parameter in here: Response.Write("<script language='Javascript'>window.open('ReportUmpireGrading.aspx')</script>")
HelloI am using this line of code to start a page for my report but I now need to pass  string parameters to that new page being popped-up. Response.Write("<script language='Javascript'>window.open('ReportUmpireGrading.aspx')</script>")Can I do it?ThanksI think, therefore I am Is this what you are after??? Response.Write("<script language='Javascript'>window.open('ReportUmpireGrading.aspx?q" & asdf & "&e=" & sdfg &"')</script>")EricPascarello.com | Twitter epascarello | LinkedIn Response.Write is evil. What A1ien51 has written is correct...

<script language='JavaScript'>location.href="#control"</script>
I tried to use asp to register this block of script into the page to direct the page to the control that the user was working on before postback, it works fine on IE, however, when I try it on netscape, the page is not showing but when I do view source, all the code are there. Anybody knows what happened and how to fix it? Thanks in advance. My guess would be that Netscape just happens to be pickier about the url starting with a hash. Try using the entire url plus the hash and see if Netscape behaves better. > Try using the entire url plus the hash Hmmm ... that might actua...

Why Response.Write("<script>window.open("newWind.aspx','report','');</script>") not working?
I need to open a new web browser of url=newWind.aspx and tried the code below; Response.Write("<script>window.open('newWind.aspx','report','');</script>")However nothing happens, what can I do to make it work? Try RegisterClientScriptBlock("OpenWin","<script language=javascript>window.open('newWind.aspx','report','');</script>")I think that is the name of it...Also look at RegisterStartupScriptBlock (I think)MajorCats Thanks. But, it was same difference. Is there anything that blocks the new browser from showing up in the setting of IE or system?   &nbs...

Trying to load user control Dynamcially but getting error " Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"
I am tired of this error and now writing a post.  My Web application has two pages. Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.     protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)  { if (ddlViewReport.SelectedIndex == 1) { Session["ReportType"] = ddlViewReport.SelectedIndex; Response.Redirect("RepReportingPage.aspx"); int crosspagevalue = ddlViewReport.SelectedIndex; } if (ddlViewReport.SelectedIndex == 2) {...

Control 'c' of type 't' must be placed inside a form tag with runat="server"
Hello, I'm trying to troubleshoot a problem I'm having with a 3rd party grid control but my test program give this error. Control 'myButton' of type 'Button' must be placed inside a form tag with runat="server" My code follows - when I add tables, rows, cells and buttons in this manner in the real program, I don't get the error but the button doesn't remember its pre-postback settings. What I want to do is toggle the CssClass when the button is clicked and show/hide other controls in the TableCell derived class also based on this value. Do I have to store the b...

workaround for "Control 'myHiddenControl' of type 'HiddenField' must be placed inside a form tag with runat=server"
Hello,I have an old classic asp page (myclassic.asp) that's posting to an ASP.NET 3.5 page (mypage.aspx) mypage.aspx uses a web control (mycontrol.ascx).  mycontrol.ascx has a form with a runat=server attribute and some server side controls in its server side form.  When I click on one of the server side buttons on mycontrol.ascx it's doing a post back to mypage.aspx.mypage.aspx has some code in it's pre_render event that reads some values from the requesting page (myclassic.asp) something like:  strAction = Request.Form("Action") This code causes proble...

Update Panel, Timer and Response.Write("<script language='JavaScript'>... issues
I have an Update Panel with a Timer in it. The timer goes off every xx amount of minutes. In the Timer.Tick() event I have C# code that I run to check data then at the end if a scenario is true I popup an alert windows with Response.Write("<scipt language='JavaScript'>... The problem is that the Response.Write will create an error every time the Timer goes off. IE gives a message box with error regarding Response.Write(). From what I have read you cannot use the Response.Write in this manner. How can I call the JavaScript on the Time.Tick() event to pop up the Warning Window?Protec...

<script language="javascript" runat="server"> can't be used?
I place this inside on a content page: <script language="javascript" runat="server"> function ontextchange() { document.getElementById("ctl00_ContentPlaceHolder1_lbl_CatchInfo").innerHTML = "change in text or whatever"; } </script> and get an error saying JavaScript can't be used as another language has been stated by the CodeFile-attribute...? It works if i remove the runat=server tag----What is wrong??? javascript is a client side language. take out the "runat =server" part and see what happens Becaus...

Problem with Response.Write("<script>alert('Msg');</script>")
Hi, My problem is this: Response.Write("<script>alert('Messaje');</script>") Response.Redirect("frmxxx.aspx") Thats my code, and it redirects me automatically to frmxxx.aspx without showing me any alert(); but when i coment the 2nd line (Response.Redirect()) it shows me the alert() box :S. Anyone Knows how can i solve this problem? thx.  Regards, the entire Response object is built before delivery to the page, and the Redirect intercepts this and navigates away. You would need to pass this all to clientside code if you want the Alert(), ...

Problem creating custom controls
Hi, I'm trying to create a custom web control and I'm having some problems. When I use the register directive to point to the source for my control I get the following error: "The 'Src' attribute is not supported by the 'Register' directive." Is that true? 'Src' pops up as one of the options as I type in Visual WebDev. Is there a better way to do this? Use 'Assembly' instead? Any tips on Assemblies will be greatly appreciated:-) Cheers. First, what does the code look like? Second, what version of ASP.NET are you using? This article might make the u...

Response.Write("<script>window.open('info.aspx')</script>"); causes font size to change on GridView_SelectedIndexChanged
Hey guys, Does anyone know why this is happening? If I redirect to a URL into a new window using the above code, it causes the font size to be gigantic after the postback. It happens only in IE though. Is there a known solution for that or another way to redirect into another window with the GridView_SelectedIndexChanged Event? TIA! Its because the text is displayed outside of the HTML decleration. If you check your HTML source code it will look like this:<script>window.open('info.aspx')</script><HTML>etc................. You may be better off have a literal con...

Custom Server Control with Panel inside complains about "missing required attribute 'runat'"
I have build a Custom Server Control: using System;using System.ComponentModel;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace iStruction.WebControls{ /// <summary> /// MyCompositeControl /// </summary> [ToolboxData("<{0}:MyCompositeControl runat=server></{0}:MyCompositeControl>")] [ParseChildren(true)] [PersistChildren(false)] public class MyCompositeControl : CompositeControl { private TestPanel _panel; /// <summary> /// Template /// </summary> [B...

Give access to non virtual folder through configuration entry? ERROR: <location> path attribute must be a relative virtual path. It cannot contain any of '?' ':' '\' '*' '"' '<' '>' or '|'.
I have a webpage running under a virtual directory that is mapped to d:/webapplication that produces an excel spreadsheet, the page calls a library object that generates a report and places it in a folder d:/attachments. This folder is not in the virtual directory. When I access the webpage i click a button and it attemps to return the created spreadsheet as a mim content type application/vnd.ms-excel. However i getting redirected back to the login page of the application. Ive also noticed that the excel spreadsheet has not even been created at this location. So assuming this...

Web resources about - How to put Response.Write("<script language='javascript' type='text/javascript'>") into custom server control - asp.net.custom-server-controls

Resources last updated: 1/16/2016 6:02:36 AM