.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Adding script in code behind

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :ASP.Net
Hi, I am trying to add a javascript code from onLoad method. I use StringBuilder to generate the code and have to add some dynamic values inside the code.StringBuilder sbScript = new StringBuilder(); sbScript.AppendFormat("document.write('<table border=\"1\"><tr><td width=\"{0}px\">'); ", sWidth); sbScript.Append( "if(document.layers){ "); sbScript.AppendFormat( "document.write('<ilayer id=\"ns4div\" width=\"{0}px\" height=\"{1}px\"> ", sWidth, sHeight); sbScript.AppendFormat( "<layer id=\"ns4div1\" width=\"{0}px\" height=\"{1}px\" onmouseover=\"sspeed=0;\" onmouseout=\"sspeed=restart\"></layer></ilayer>') ", sWidth, sHeight); sbScript.Append( "if(document.getElementById||document.all){ "); sbScript.AppendFormat( "document.write('<div style=\"position:relative;overflow:hidden;width:{0}px;height:{1}px; ", sWidth, sHeight); sbScript.AppendFormat( "clip:rect(0 {0}px {1}px 0); onmouseover=\"sspeed=0;\" onmouseout=\"sspeed=restart\">'); ", sWidth, sHeight); sbScript.Append( "if(gekso==0&&operbr==-1)"); sbScript.AppendFormat( "document.write('<div id=\"iens6div\" style=\&q

View Complete Post

More Related Resource Links

Foundations: Adding Code Access Security to WCF, Part 2


This month's column continues the discussion around code access security in WCF and partially trusted services.

Juval Lowy

MSDN Magazine July 2008

Windows Script Host: New Code-Signing Features Protect Against Malicious Scripts


Downloading scripts from the Web or e-mail leaves users vulnerable to security risks because scripts can't be signed. But now developers can use Windows Script Host (WSH) to hash scripts so users can verify their source and safety. With WSH, scripts can be signed or verified using all the same tools ordinarily used to sign EXE, CAB, DLL, and OCX files. This article discusses public-key cryptosystems, the process of signing and verifying scripts in WSH, and several warnings about attacks that could potentially be made against cryptographically secured scripts and ways in which to avoid them.

Eric Lippert

MSDN Magazine April 2001

.net 3.5 in conjunction with CRM 4.0 email router adding code to subject line of emails causing spam

We use CRM 4.0, which is using .net framework 3.5 SP 1.  Emails sent out of CRM go through and email router and the subject line of these emails is getting "=?us-ascii?Q? added to the beginning of the subject line and "?= added to the end of the subject line. This is causing a large amount of our emails getting spammed. I was told by the CRM support that this is an issue with .net 3.5 and won't be fixed until .net 4.0, which CRM won't support for another year.  Is there not a .net 3.5 patch that can address this?

Adding source redirect code to end of a URL which used a dynamic data value

I'm trying to add some source redirect code to the end of a URL in a Data Form Web Part on a simple SharePoint aspx page. This is the basic url: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID} However I want to add a source redirect to the end of the URL so that it returns to a particular page rather than the list's default page. I have tried all of the following: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}&source=/itservices/Pages/MyOverview.aspx That causes an error in the web part stating "This Web Part does not have a valid XSLT stylesheet: Error; A semi colon character was expected". I tried replacing the ampersand with the URL encoded character: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}%26source=/itservices/Pages/MyOverview.aspx But when opening from this URL the form contains no data. What am I missing or can this not be done? Thanks.  

Script error in adding users in sharepooint Site

I seem to have a problem when trying to enter new users on a newly built site (SharepointSite). I cannot select the new user option the grant permissions dialog doesn't appear. I'm running MS office 2003 sp3 and ie 7 regards Alan Bateman.

Adding a custom form to List's FormCollection in code

Hello, In a site within a site collection, using SharePoint Designer 2010 we have created custom Display, Edit and View forms and assigned them to the Item content type of a custom list as it's default forms. When looking at the Forms property of the list, I can see all six forms listed: the three original forms (DispForm.aspx, EditForm.aspx, NewForm.aspx) and the three custom forms (displayifs.aspx, editifs.aspx, newifs.aspx). Each site in the site collection has this custom list and I want to add these three custom forms to the custom list in each site in the collection as the default forms for items. In code I have tried copying the files from the Item subfolder of the first custom list to the Item subfolder in each list in each site, and then setting the properties for the Item content type's default forms to point to these new files (e.g DisplayFormUrl = "~list/Item/displayifs.aspx"; EditFormUrl = "~list/Item/editifs.aspx"; NewFormUrl = "~list/Item/newifs.aspx";) and I have also copied the fourth file template.asxn to this folder in each list. However, I have not found how to add these new files to the Forms property of the list iteself, as this property is read-only. It still only contains the three default forms. Is this possible to do in code? When I try to open the Display form or Edit form in

Can I invoke a client side script from server side code

Hi is it possible to involk a client side script from the server side code without any interaction from the client side?Such as a popup or alert box?I know I can code this with the page load or the click event, I would like to call the alert from within my serverside code and trigger the action from there.Thanks

Adding logic to the Search Core Results web part - Manipulation in code or XSL?

Hi,I need to manipulate the search core results web part, so that:- It will display a check box for each result- It Will have an additional button. When clicking on this button the checked results should be copied to a grid view.Do you have any idea how it can be done?I am not sure what is the correct way to do it – in the client side via the XSL Editor or in the server side with the C# code.Thank you so much for your help,Regards,SP beginner.

adding onload event from code behind for Google Maps

Im working with Google maps start turoail: http://code.google.com/apis/maps/documentation/javascript/tutorial.html#HelloWorldAs you can see there's a line: <body onload="initialize()">Now since, I want to have Google Maps on page A.aspx within a masterpage main.master, I dont have the <body> tag available to me in the A.aspx page.I preferably DONT want to have the body tag as runat="server", since Google Maps is not relevant for all pages and I dont like a server control when its not needed as they slow things down (even a bit).I tried this in A.aspx.vb, but it didnt work:Dim javaScript As New StringBuilder        javaScript.Append("<script type='text/javascript'>")        javaScript.Append("window.document.body.onload = initialize();")        javaScript.Append("</script>")        Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "BodyLoadUnloadScript", javaScript.ToString())How can I add the onload event from code behind?

EXPERT: Method error 500 in dropdown (solution is NOT adding System.Web.Script.Services.ScriptServic


Please only answer if you have read the full question!!

Ok...this thing is driving me crazy!!!!

I keep getting a method error 500 in my dropdown box.

All the posts on the web come with the same solution, but it doesnt work for me!
The code seems SO simple and consists of so few lines....but it just doesnt work!



<asp:DropDownList ID="ddlCountries" runat="server">

<cc1:cascadingdropdown ID="cddCountries" runat="server" Category="Country" Enabled="True" LoadingText="Loading...please wait." PromptText="Choose a country" ServiceMethod="GetCountries" ServicePath="geolocation.asmx"     TargetControlID="ddlCountries"></cc1:cascadingdropdown>

<%@ WebService Language="VB" CodeBehind="~/App_Code/geolocation.vb" %>

<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
 Public Class geoloc

How could Transfer a simple object that is created in asp.net to java script code and worked with it


Hi Experts.

I have a simple call in asp.net code behind. There are two variable i, j and some methods in . Like:

Class Test()

{              int i; string str;

                Public getI(int){//.}

Public getJ(int){//.}


Is there any way to have the same class in javascript? I want to create a simple object form this class and initiated its variables and passed it to javascript code and worked with it? How can I do it?


Adding XML doc template to existing code

Hi Everyone,
    I would like to know if there is any tool that can add XML documentation templates to a source code.  Basically, I want to add XML documents to new source code. The existing source does not have XML documentation for existing classes, so when I add XML documentation to new class, I get compilation error indicating no XML documentation for old classes.  Is there a tool that is available that can parse the source code and then add XML doc templates ?

For example,
If I have the following code:

class TypeByName




adding dynamic script


    <asp:Panel ID="Panel7" runat="server">
        <div id="Div4" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" />
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

code behind:

        protected void Page_Load(object sender, EventArgs e)
            if (CheckBox1.Checked)
                String csName = "CounterScript";
                Type csTyp

Adding to Published links to Office client applications via code


For a current sharepoint 2007 moss project it would be nice to automatically put certain document libraries into the word save as menu for certain users.

This can be achieved using Published links to Office client applications.

To automate this it would be nice to develop a script that automatically a link into Published links to Office client applications based on the document library security. 

The web service PublishedLinksService only has method .GetLinks and I cannot see anything in the object model.

If anyone knows if this can (or definately cannot) be done then the guidance would be very much appreciated.

Adding script to an onClick event in a Hyperlink control



I need a little help with the formatting for an on click event in a hyperlink control:

<asp:HyperLink ID="HyperLink" runat="server" onclick="test('<%=Page.ResolveUrl("~/secure/club-officials/add-new-official.aspx")%>');" >Add New Official</asp:HyperLink>

I get an error with the using the <% %> within the onclick.

Many thanks

Adding a new field to a table via script in sql server management studio

I know how you can script to and create a new table but how about adding a new field to this table? For example: how would i add a new varchar(50) field named mynewfield?

USE [example]
/****** Object: Table [dbo].[Password]  Script Date: 10/26/2010 10:17:30 ******/
CREATE TABLE [dbo].[Password](
	[user_id] [int] NOT NULL,
	[password] [varchar](30) COLLATE SQL_Latin1_General_CP850_BIN2 NULL,
	[response1] [varchar](40) COLLATE SQL_Latin1_General_CP850_BIN2 NULL,
	[response2] [varchar](40) COLLATE SQL_Latin1_General_CP850_BIN2 NULL,
	[response3] [varchar](40) COLLATE SQL_Latin1_General_CP850_BIN2 NULL,
	[user_id] ASC

ALTER TABLE [dbo].[Password] WITH CHECK ADD CONSTRAINT [User_Password_FK1] FOREIGN KEY([user_id])
REFERENCES [dbo].[User] ([id])
ALTER TABLE [dbo].[Password] CHECK CONSTRAINT [User_Password_FK1]

Adding additional code to jTemplate



I have following function to apply the jTemplate, I was wondering if there a way to append an additional HTML around this code

function Success(data, status) {

like adding a table, ul and ui tag etc, I tried append without any success:

function Success(data, status) {


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend