CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 8/13/2007 7:30:42 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 84 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
AdmiralPrinting
Asp.Net User
HTML form won't work from within contentplaceholder8/13/2007 7:30:42 PM

0

I am trying to construct a web site with a master page, and content pages based on that master page. On one of these pages, I wanted to use a simple HTML form that I designed. The HTML form works perfectly well when it's put in a regular HTML page, but it does nothing when I place it inside a contentplaceholder control. In fact, I seem unable to get things inside my contentplaceholder controls on individual pages to do anything except act as static content: simple scripts don't work on any of the controls (I can't seem to "get to" the objects with javascript; I've done a number of test loops to try to crawl through the object model and I'm getting nowhere). Everything looks as expected, but nothing behaves as expected. I am new at this, so please don't laugh if this is something obvious. Sorry I'm probably not explaining this well. Any help would be appreciated.

Thanks

Jenny

huenemeca
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/13/2007 8:03:22 PM

0

Can you post some source code so I can see exactly what you are doing?  It could be a naming issue with the master page.

http://www.2DoNext.com
Lee Dumond
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/13/2007 8:08:55 PM

0

 Are you using <form> tags around the form you've placed in the content page? If so, that would cause a problem, as the Master page will already have placed the entire page inside a <form>. You can't have a <form> inside another <form>.

As far as addressing the DOM using JavaScript, that can be tricky, because ASP.NET sometimes renames object IDs. Like, what you named myTextBox could now be ctl00_myTextbox or something similar. This happens when you have server controls that contain other server controls. So, a script that works great in a regular HTML page could break. You need to find out if this is happening (View Source) and change the IDs in the JavaScript you are using to target the object to what is getting rendered on the client.

Stop using test loops to crawl the DOM. That is so.... 2006. ;-) Get FireFox, then download Firebug 1.0 !!!


==================================================
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we all know you have been helped.
AdmiralPrinting
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/14/2007 2:01:27 PM

0

OK. I actually tried it without the <form> tag in the contentplaceholder, and it still didn't work (no surprise there, since the aspnet form doesn't have the same submit instructions as my other <form> tag did). So are you saying you can't use a form on a content page that uses a master page? That seems very odd to me, especially since the "Mastering" book I got for Web Developer says nothing about this being a limitation.

Also, I already tried to find out the "real" IDs (yes, I know they get mangled) both by looking at the source and by using a JavaScript test loop (which of course is sooo 2006). Anyway, the test loop gives me all sorts of references to the controls within my form, but when I try to directly refer to these in JavaScript using the resulting IDs, it returns an "undefined" value. It's as if they don't really exist.

So anyway, I'm not sure if posting code is going to make this any clearer. It's really sort of two separate problems: 1) an HTML form won't work within a contentplaceholder; 2) I can't make JavaScript "see" any of the stuff I have in the contentplaceholder.

Example of 2):

(JavaScript function loaded by the master page from a file, which works fine when "called" by an item on the master page):

function SwapImage(ctl, s) //changes a control's image source

{

var btn = theForm.children[ctl];s = "../../../Admiral/images/" + s;

btn.src = s;

}

The "calling" HTML within the contentplaceholder:

<img id="imgHome" src="../../../Admiral/images/home.jpg"

onmouseover="SwapImage('imgHome','homeover.jpg');"

onclick="GoTo('Default.aspx');"

onmouseout="SwapImage('imgHome','home.jpg');" alt="Admiral Printing Home" />

 

Example of 1):

<%@ Page Language="C#" MasterPageFile="~/Admiral.master" AutoEventWireup="true" CodeFile="Quote.aspx.cs" Inherits="Quote" Title="Get a Quote" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<h1 style="font-family: Verdana" align="center">

<hr id="HR1" align="left" width="730" />

Get a Quote</h1>

<p style="text-align: center; font-family: Verdana; font-size: 10pt">

<strong>

Thank You For Giving Us the Opportunity To Serve You<br />

</strong>

Please enter your information below and we will contact you as soon as possible.

You can expedite the process by filling in as much information below as possible.

But don't panic if you don't know what some of these items mean; just fill out what

you do know. If we do need additional information or clarification in order to determine

a price, we will contact you prior to completing the quote.</p>

<div style="text-align: left; font-family: Verdana; font-size: 10pt">

<form id="frmQuote" name="Quote"

action="mailto:[email protected]?subject=Quote"

method=post enctype="text/plain">

<p >

Name:

<input id="txtName" name="Name" type="text" style="width: 295px" language="javascript" onclick="return txtName_onclick()" />&nbsp; Company:

<input id="txtCompany" name="Company" type="text" style="width: 295px" /><br />

Email:

<input id="txtEmail" name="Email" type="text" style="width: 307px" />&nbsp; Phone:

<input id="txtPhone" name="Phone" type="text" style="width: 306px" /><br />

Fax:

<input id="txtFax" name="Fax" type="text" style="width: 320px" />&nbsp; Cell:

<input id="txtCell" name="Cell" type="text" style="width: 320px" /><br />

Subject:

<input id="txtSubject" name="Subject" type="text" style="width: 662px" /></p>

<p >

Is this job:

<input id="rdoNew" type="radio" name="TypeJob" value="New" />

NEW&nbsp;

<input id="rdoRerun" type="radio" name="TypeJob" value="Rerun" />

RERUN&nbsp;

<input id="rdoChange" type="radio" name="TypeJob" value="Rerun w/Change" />

RERUN w/CHANGES</p>

<p>

<input id="Submit1" type="submit" value="Send" />&nbsp;</p>

</form>

</div>

</asp:Content>

Hope this makes some sense (and I hope this submits correctly with all this HTML in here) -- thanks again for trying to help.
Lee Dumond
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/14/2007 7:31:12 PM

0

 Wow... where to begin? Surprise

I am only going to address the form issue here, as that's your main problem for right now. Once you get that ironed out, you can tackle the image swapping.

First... forget everything you ever learned about HTML forms. It no longer applies. You're in ASP.NET-land now. In ASP.NET, all pages are "forms".  The entirety of each and every page. Even if it doesn't have a single textbox or button on it. Period, end of story.

You should have seen that your Masterpage has a <form></form> tag that sets all the content inside a form. You have another form tag inside your placeholder. When the page is rendered, that's a form inside a form, and that's a no-no.

Second... don't use mailto: to send a form. It's very bad... ummm... form. ASP.NET already has the classes of the System.Net.Mail namespace that lets you send mail from the server. You can use an <asp:Button> control, and in its Click event write code to compose and send the mail. This will tell you all about it:

http://aspnet.4guysfromrolla.com/articles/072606-1.aspx

Third... since this is an ASP.NET form, you really need to be using ASP.NET server controls to build it.

I know I haven't answered your question "directly", and that's on purpose. I could have, but that's not going to help you grasp the concepts you need to learn. I've given you a good start, especially with that link aboive. Read it. Then get a couple of really good ASP.NET beginner books and read those too.
 

 


==================================================
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we all know you have been helped.
AdmiralPrinting
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/14/2007 8:07:54 PM

0

I appreciate your advice, Lee. I'm just saying it was my understanding that you don't have to do everything server-side just because it's ASP.NET. In fact, I thought I was using a good "beginner book" (the "Mastering" series), and that even says it's often better to use a plain HTML form for something simple and not "secure," because of the performance advantage of client-side processing. The book even has a whole chapter on client-side scripting in ASP.NET (it just doesn't address how to do this within a content page that uses a master page).

If it can't be done that way, then it can't be done. If it's just not possible to mix client-side scripting with content within master pages, I will obviously have to use server-side processing, which I was trying to avoid on the simpler pages of my site to improve performance.

As I said, I am very new to ASP.NET in particular, so I'm sorry if this sounded like a dumb question. It just seemed to me you should be able to do client-side scripting on contentplaceholder content just as well as you can do server-side scripting. I guess I'm wrong.

Thanks.

Lee Dumond
Asp.Net User
Re: HTML form won't work from within contentplaceholder8/14/2007 9:09:45 PM

0

AdmiralPrinting:
and that even says it's often better to use a plain HTML form for something simple and not "secure," because of the performance advantage of client-side processing. The book even has a whole chapter on client-side scripting in ASP.NET
 

Yes, of course you can do client-side processing in ASP.NET, and you're right -- it has some advantages. However, posting a form using "mailto:" is not "client-side processing," as you call it. I invite you to read more about this as well:

http://classicasp.aspfaq.com/email/should-i-use-form-action-mailto-to-mail-the-results-of-a-form.html

 

AdmiralPrinting:
If it's just not possible to mix client-side scripting with content within master pages...

It's very possible. It's done all the time. Declaring "it can't be done", just because you haven't figured out how to do it yet, is kind of self defeating, don't you think? 

AdmiralPrinting:
It just seemed to me you should be able to do client-side scripting on contentplaceholder content just as well as you can do server-side scripting...

You can. See the comment above.
 

And the only dumb question is the one you fail to ask. 


==================================================
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we all know you have been helped.
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET 2.0 MVP Hacks and Tips Authors: David Yack, Joe Mayo, Scott Hanselman, Fredrik Normén, Dan Wahlin, J. Ambrose Little, Jonathan Goodyear, Pages: 400, Published: 2006
Professional VB 2005 Authors: Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Rama Ramachandran, Kent Sharkey, Bill Sheldon, Pages: 1066, Published: 2006
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008

Web:
HTML form won't work from within contentplaceholder - ASP.NET Forums It's really sort of two separate problems: 1) an HTML form won't work within a contentplaceholder; 2) I can't make JavaScript "see" any of ...
ContentPlaceHolder under a DIV tag - Visual Studio Design view ... I have a master page with ContentPlaceHolder under a html Div tag. .... Why Values in Unbound Form Controls Don't Persist · 10 Tips to Avoid Information ...
Microsoft Expression Expression Web Why does asp ... They don't want to work together. ... and now it doesn 't work again. .... . . . ...
K. Scott Allen : The ContentPlaceHolder – Not Just For Content The validation engine in the Visual Studio 2005 IDE doesn’t believe a ...
Login Control/Validation Summary within Content Placeholder I have created a web form that then uses this master page. Within the content placeholder, I have placed a Login control (Login1) and a ...
Master Pages in ASP.NET 2.0
... As it is now, it is possible to create content pages that don’t use the master page by simply ...
Set ContentPlaceHolder dinamically - ASP.NET Forums So far I try to put the contentplaceholder inside an UpdatePanel and the .... a CalendarExtender doesn't work and is shown with no style. ...
JavaScript on my ASP .NET site can't access HTML elements ... Why won't this simple test example work either? ... the javascript code that you don't put within a function is executed ...
Content Placeholder Creating Space Between Divs - ASP.NET Forums . CSS:. body { margin:50px 10% 50px 10%; padding: 0px; ... The ContentPlaceholder control doesn't render anything, so it's not that. ...
Writing directly to ContentPlaceHolder - Application Development Forum This is a discussion on Writing directly to ContentPlaceHolder within the DOTNET forums in Framework and Interface Programming category; ...












can i solve my problem with master pages?

masterpages in usercontrols ? how ?

!doctype

treeview and postbacks in ie

css - bottom,middle please

master page class type error

why does the sub menu invisible?

<asp:wizard and javascript question

how to have a webpage url 'auto-fill' a contentplaceholder?

masterpage & content placeholder markup

treeview frozen

master pages dropdownlist component access to content page

asp.net menu set non-selectedable item style

what is the easiest way to add a style to body? i want it inline, not in css files.

menu

treeview to work with javascript disabled,use treeview across pages (treeview present on master page)

set the default page of the folder

why is the javascript for a menu control obtained from webresource.axd????

can sitemenu access a url outside of your site?

menubar using sitemap

pulling user name from loginname control to textbox

forum sitemap page

how can i disable link for treeview control nodes besides leaves of the control?

web.sitemap overwrite programmatically

i don't want to design a web page using vwd

concept behind the master page

turn off menu during change password

blank image next to leafnode in treeview

separators for menus that use sitemap file

cisco vpn causes site with themes to slow down

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT