Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 28th, 2006, 03:12 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
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


  #2 (permalink)  
Old August 28th, 2006, 03:15 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
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();


  #3 (permalink)  
Old August 28th, 2006, 04:26 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
  #4 (permalink)  
Old August 29th, 2006, 12:10 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
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



  #5 (permalink)  
Old August 29th, 2006, 12:34 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:57 PM.


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