Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2006, 03:12 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using javascript for dynamic asp: control

Hello All:

Below appears the source for a trivial ASP.NET 2. micro project for testing javascript's ability to build window pages dynamically. The program below works.

However, what does not work is substituting an <asp:Image> control for the <img> html control. I've tried for a full day to make the substitution work but have failed.

Anyone tell me how to make it work?

BETTER YET, can anyone tell me the name and ISBN number of a book that would show me how to dynamically create windows pages with lots of different kinds of <asp:XXcontrolXX>s?

VictorVictor


 
Old August 28th, 2006, 03:15 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Forgot to attach the source code.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Dynamic Pop-up Example</title>
</head>
<body>
    <form id="form1" runat="server" >
    </form>
</body>
</html>
--------------------------------------------------------------------------------
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Me.ClientScript.RegisterClientScriptInclude("Defau ltPage_javascript_Key", "Default.js")
    End Sub
End Class
--------------------------------------------------------------------------------
// JScript File
 var popwindow = window.open("","","top=40,left=30,width=500,height =250");
    popwindow.document.open();
    popwindow.document.write("<title>Pop-up</title>");
    popwindow.document.write("Dynamic Pop-up Page<br/>");
    popwindow.document.write("<img src='HikeFT.gif' alt=''>");
    popwindow.document.close();


 
Old August 28th, 2006, 04:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

ASP.NET is a server side technology, while JavaScript is a client side technology.

You can't create server side pages with a client side language and expect things to work. For a server side <asp:Image> to become a client side <img> it has to be compiled and be part of the whole ASP.NET processing pipe-line after which it ends up as a client side <img /> tag.

What is your intention with this? Why do you think it's useful to create "server side pages" at the client and why do you want to do this?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old August 29th, 2006, 12:10 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

Thanks for your response. I am interested in creating asp: controls by using javascript, for two reasons.

1. I am interested in learning how much I can do using javascript. Obviously I can it to create html controls on a page and manipulate any of the page's DOM objects. I had hoped that such creation would include an asp: object. Guess not.

2. The particular app I am working on will offer users, who are not programmers, but rather semi-skilled computer users, the ability to build asp pages for sending to the server. I picture something like a wizard facility where the user specifies enough detail for me to build the asp page dynamically. I had hoped to use javascript for this. For example, in my app, a user needs to be able to build a page containing a schedule of future monthly activities for a hiking club. The particular line items (hikes) are not generally known until club meetings have occurred wherein the details of hikes are decided upon. Once the details have been established, when, where, description, etc. I want the user to enter the details into textboxes, etc, and click a Build button. The functionality under the Build button builds the asp page, sends it to the server, and integrates it into the overall set of server pages. It's important that I remove myself from the app, and not build pages myself. I'm trying to find a way for the unsophisticated user to do that.

Instead of using javascript to do all this, my only other hope would be to get into the meta code and/or MicroSoft Intermediate Language . And, I am new to both javascript and ASP.NET 2.0. So I don't think I have the skill to do that (much less the time to learn how to write MSIL). Finally, I am one developer working alone and time is a definite scarce resource. If including the 'wizard' capability isn't simple or readily available for implementation via some simple mechanism,then I will have to abandon that app feature.

Thanks for your help.

VV



 
Old August 29th, 2006, 12:34 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right, I see. But since JavaScript runs at the client, this plan will never work.

However, MSIL is on the other side of your possibilities. With MSIL, you are probably not going to solve this as well.

IMO, you have a few options:

1. Use an ASPX form to generate controls at run-time. E.g. in Page_Load, you can do this:

Button myButton = new Button();
// Do something with the button
myPlaceHolder.Controls.Add(myButton);

This injects the button control into the Controls collection of the PlaceHolder control. This is a trivial example, but much more is possible.

2. Use a database for dynamic stuff. Depending on your needs and requirements you may not need all this complicated stuff. Instead, design a smart database schema that can hold variable data. Presenting the data may be difficult though, but it all depends on what you are doing.

3. Use a client side UI (with ASP.NET forms) and server side code to create new ASPX pages on the fly. You could simp,y build up a complete string with the final code, and then write it to disk.

4. Alternatively, you can take a look at the System.CodeDom namespace that allows you to create and compile code on the fly. I haven't done much with it, other than play with it from an academic perspective, but it's an interesting technology.

But, personally, I don't think you need to go this complex route. I think with a smart design and UI, you can build flexible user interface that suits your needs, possible using option 1 to create controls on the fly.

Did you ever overcome the shock of hacking from this thread: http://p2p.wrox.com/topic.asp?TOPIC_ID=48504

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic control (c# ASP.net) Hemang ASP.NET 1.0 and 1.1 Basics 0 June 28th, 2007 08:34 AM
Passing asp control id to javascript jazzcatone ASP.NET 1.0 and 1.1 Professional 0 October 18th, 2006 01:38 PM
make javascript code more dynamic crmpicco Javascript How-To 3 October 17th, 2005 05:40 AM
make javascript code more dynamic crmpicco Javascript How-To 1 September 27th, 2005 11:44 AM
Javascript Dynamic dropdown Menu itHighway Javascript How-To 0 July 24th, 2005 10:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.