Choosing a page based on user input - forms?

rated by 0 users
This post has 8 Replies | 3 Followers

Not Ranked
Posts 7
Points 110
gregray Posted: Wed, Mar 12 2008 2:00 PM

There has got to be a simple way to do this, but I'm losing my hair over it. 

I understand that in CS you can't use <form> tags, but I should be able to use form controls - shouldn't I?

I've created an article that I link to as a content page.  I'd like to have a single text box with an enter button that runs the submitted text through a script.  I can get the controls to show up, but it won't run the script.

Please Help! 

Here is the outline of the html that I added to the article:

<SCRIPT language=vbscript runat="server">
   Sub btnclk
     strZIP = trim(zip.text)
     If len(strZIP) = 0 Then
          Response.Redirect "locatorpage.aspx"
     End If
     Select Case Left(strZIP, 3)
                                Case "551"
                                                Response.Redirect "dealer1.aspx"
                                Case "552", "553"
                                                Response.Redirect "dealer2.aspx"
                                Case Else
                                                Response.Redirect "factorydirect.aspx"
      End Select
    End Sub
</SCRIPT>

<P mce_keep="true">Please Enter your 5-digit zip code to locate the dealer nearest you:</P>

<INPUT name=zip runat="server">
<INPUT type=button onclick="btnclk" value=Enter name=zipsub runat="server">

 

At the moment, the subroutine isn't even getting called.... 

If I am off base, or if there is another method, that would be fine.  If there is a way to embed HTML forms that I can't figure out that would be great.  Any help would be appreciated. 

 

Best Regards,

Greg

  • Filed under:
  • | Post Points: 20
Top 10 Contributor
Posts 5,284
Points 49,035
CS Developers

Not being able to use <form> tags is how ASP.NET works, not something from CS.  Actually, you do use a <form> tag, but it expects 1 per page, usually at a higher level, and it needs to have runat="server".

Secondly, you can't just use an <input> tag with an onclick and have it postback.  For postbacks to work and have them call your methods, you need to use the actual ASP.NET WebControls.  IE, use <asp:Button id="button" onclick="btnclick" text="Enter name" runat="server" />.

The <INPUT> elements that have runat="server" true are not handled as WebControls, they are handled as HtmlControls, where the functionality is much more plain.  They don't enable the advanced functionality like postbacks.  You normally don't use them for form controls, typically they're more commonly used with other HTML controls like span/div/etc tags you need to control server side.

  • | Post Points: 20
Not Ranked
Posts 7
Points 110
gregray replied on Wed, Mar 12 2008 2:46 PM

 Thanks for the quick reply.  The ASP.NET controls don't show up on the rendered page.  So I must be missing something there.  Just to be clear:  This is a page that I created with the Create/Manage Articles option in the control panel.  I'm now adding to the page with with the built in html editor.

This is how I've modified it based on what I think I understood you to say:

<SCRIPT language=vbscript runat="server">
   Sub btnclk
     strZIP = trim(zip.text)
     If len(strZIP) = 0 Then
          Response.Redirect "locatorpage.aspx"
     End If
     Select Case Left(strZIP, 3)
                                Case "551"
                                                Response.Redirect "dealer1.aspx"
                                Case "552", "553"
                                                Response.Redirect "dealer2.aspx"
                                Case Else
                                                Response.Redirect "factorydirect.aspx"
      End Select
    End Sub
</SCRIPT>

<P mce_keep="true">Please Enter your 5-digit zip code to locate the dealer nearest you:</P>

<?xml:namespace prefix = asp />
<asp:textbox id=zip runat="server"></asp:textbox>
<asp:button id=button onclick=btnclick runat="server" text="Enter"></asp:button>

 

The <?xml:namespace was added by the html editor on closing.  That's not anything I'm familiar with.

The rendered page has no textbox or button on it at all.  Did I missunderstand?

Thanks.

 

  • | Post Points: 20
Top 10 Contributor
Posts 5,284
Points 49,035
CS Developers

Ahh, I didn't realize this was a page/article within CS.

You cannot put code in any posts, articles, or content managed by CS.  To include code, you would need to create an actual file on the filesystem with the code you want and integrate it into the application on your own.

  • | Post Points: 20
Not Ranked
Posts 7
Points 110
gregray replied on Wed, Mar 12 2008 4:47 PM

 Okay - so if I'm following you, I can't use any server side code - hence no real forms with postbacks.   In digging through the structure though I could use client side scripting?

  • | Post Points: 20
Top 10 Contributor
Posts 5,284
Points 49,035
CS Developers

You would probably need to disable the HtmlScrubber, since otherwise it would likely remove the javascript.

In general, I would suggest that you create scripted content outside of CS.  Again, CS is meant to manage content and not scripts.  You could go in to edit one of the scripts just to change some HTMl content, it could load the HTML editor, and it might eat your javascript because it is meant to be work with embedded javascript.  Using regular, static files would be better suited in general.

  • | Post Points: 20
Not Ranked
Posts 7
Points 110
gregray replied on Thu, Mar 13 2008 7:35 AM

 Thanks for the clarification.

I think for me the instructive phrase was:"CS is meant to manage content and not scripts". 

I also understand the challenge of having the scrubber eat javascript - as Bill Cosby once put it,"I told you that story to tell you this one."

So, is there a non-developer method for accomplishing what I'm trying to do?  Namely:

I've Modified the master.master and a few config files to get my "look and feel" as a wrapper around every page.  For content pages I use articles created in the manage/create articles.  For the forums, galleries, and so on, my "look and feel", and main menu bar all carry through.  All that I need now is the ability to ask for a piece of information and redirect accordingly.

I am not a developer.  I have a good basic knowledge, a pile of reference books, and google.  Is there an easy way to create a scripted content that can be injected into the structure I'm using?

Thanks for your patience.

 

 

  • | Post Points: 20
Top 500 Contributor
Posts 48
Points 760

I would love to hear a solution for this also. My scenario involves multiple registration pages based on whether a check box is selected... Any simple solutions?

  • | Post Points: 5
Top 500 Contributor
Posts 48
Points 760

I just used a work around: 2 buttons for the user to select an option (in place of a checkbox) that direct to two different pages.

  • | Post Points: 5
Page 1 of 1 (9 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com