navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Postbacks without JavaScript?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Postbacks without JavaScript?
Page: [1]
 
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
Postbacks without JavaScript? - 4/29/2008 13:02:07   
Hello,

A search of the forums didn't find me quite what I was looking for, but my question is, is it possible to do a postback to the same page in ASP.NET without using JavaScript?

I'm building a "contact us" form, with different options available via dropdowns, and when someone chooses a dropdown, I want certain information and options on the page to change according to what they have chose (and if they decide to pick something else, I want it to change again, accordingly). I'm trying to avoid using client-side JS as much as possible because of the problems that occur if users have JS disabled, etc...
Could someone point me in the right general direction for this? I don't even know if it's possible. I've tried Googling around for examples, but the ones I've found so far all use JS to do what I'm trying to do.

Thanks,

-_Will
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 13:10:24   
I personally know of no way of doing that without 1 of 3 ways:

1. Client-side JS
2. Post-Backs
3. AJAX

I don't believe it's possible and I have tried to do that before without AJAX. But then again, AJAX falls under #1 anyways so I don't think there are too many options.



_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 14:30:16   
Hi rdouglass, thanks for the reply.

In the case of AJAX, if I wanted to guarantee that it couldn't fail (as much as such things can be guaranteed), would I have the option of having this run on the server-side? And can you tell me what kind of "grace" AJAX can afford me in terms of accessibility, like will my different options and the screen updates be visible to screen-readers and such? Or would it just be a mess of code?

Thanks!

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 15:41:54   
quote:

would I have the option of having this run on the server-side?


It wouldn't be AJAX then and would require a post-back.

You can do 'conditionals' with .NET but it's not for the 'feint of heart'. Have you considered 2 separate pages? One for clients with JS and 1 for clients without?

The only way to 'garantee' (as much as you can anyways), is to do post-backs. That can be a good thing sometimes because you can save state and avoid problems like users walking away and coming back 20 minutes later.

I have no idea how AJAX plays with screen readers. Probably not well since it is JS based.

It's difficult to say the best way. There are sooooo many "if"s in there.

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 16:01:22   
I think I'd be fine with postbacks--"screen-flicker" isn't a big concern for me. I just want to be able to ensure that this will work in the most number of browsers and devices as possible, without too much reliance on individual client-side settings. Server traffic isn't a big concern for me either, since out user base is pretty fixed and we don't particularly need to draw more users in. Plus, I'd rather not have to learn AJAX on top of everything else I'm learning at the moment. :)

So, conceptually-speaking, I should be able to have a .NET page that can post back to itself and populate various portions of the page depending on whatever "option" the user has chosen from the drop-down, and without JavaScript?

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 16:08:48   
quote:

I think I'd be fine with postbacks--"screen-flicker" isn't a big concern for me.


You can cut that back dramatically by adding SmartNavigation in the page declaration as in:

<%@ Page Language="VB" MasterPageFile="~/NewCompanyAdmin.master" AutoEventWireup="false" CodeFile="CompanySetup.aspx.vb"
Inherits="Members_Company_CompanySetup" title="Company Setup Wizard" StylesheetTheme="SF_NewAdmin" SmartNavigation="True" %>

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 4/29/2008 16:28:23   
Sounds good--I'll give that a try! :)

(in reply to rdouglass)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/2/2008 16:04:34   
Okay, the SmartNavigation feature seems to be giving a nicer effect than watching the whole page flicker.

And I have the AutoPostback function working with my ASP.NET drop-down list selections.

I have a question: I wanted each list selection option to populate the page with different text (and ASP.NET code) specific to that option, as opposed to having a dozen different pages.
Question: would I be better off to use ASP.NET "includes" via Response.WriteFile and refer to external .inc files of my own making, or would I be better off to just consolidate everything onto the same page and have all the text and code for each selection option available via Response.Write?


Also, is it possible to pass a parameter via URL to a <asp:dropdownlist>? For example, I want a link from another page that will bring the user to my "contact" page so that the "Webmaster" option in my dropdown list will already be selected for them, instead of making them click for it.

< Message edited by IronWill -- 5/2/2008 17:27:17 >

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 5/2/2008 17:48:24   
quote:

would I be better off to use ASP.NET "includes"


From my own perspective, I'm a database guy and data goes in the database. :) Personally, I try to restrict 'includes' to code rather than data.

quote:

is it possible to pass a parameter via URL to a <asp:dropdownlist>?


2 ways that I can think of right off:

1. If the dropdown is from a datasource, you can specify a parameter in the datasource to use a querystring, formfield value, control, etc. I'm not sure how your dorpdown is set so I'm not sure.

2. I use something like this on ASP.NET code behind pages. This works virtually in every circumstance I've tried:
                dropdownName.SelectedItem.Selected = False
                For Each item As ListItem In dropdownName.Items
                    If item.Value = theVariableYourPassing Then
                        item.Selected = True
                    End If
                Next


That has to be obviously in a .NET code block and be sure to set the SelectedItem.Selected = False first or you will error.

Hopefully those help a little.



_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/5/2008 16:43:01   
Thank you very much! I seem to have gotten the URL parameter passing as per the code you provided.

However, it seems to have knocked out the "normal" functionality of the contact.aspx page in that manually selecting an item from the list doesn't "take", the page just posts back with the default item (which isn't "selected", it's just at the top) in the list. Here is the code I have so far--I'm hoping you can spot what I'm doing wrong?

My form id is "who"...

<%

Dim contact = Request.QueryString.Item("contact")

%>

<%
If not (IsDBNull(contact)) Then
                who.SelectedItem.Selected = False
                For Each item As ListItem In who.Items
                    If item.Value = contact Then
                        item.Selected = True
                    End If
                Next
End If

%>
		
					<h1>Contact Us</h1>
	<form method="post" action="contact.aspx" runat="server">					
			<asp:DropDownList runat="server" id="who" AutoPostBack="true" EnableViewState="true">
				<asp:ListItem Value="Please Choose:" Text="--Please Choose:--" />
				<asp:ListItem Value="Bookmobile" Text="Bookmobile" />
				<asp:ListItem Value="Development Office" Text="Development Office" />
				<asp:ListItem Value="Lending Services" Text="Lending Services" />
				<asp:ListItem Value="Librarian--ADA" Text="Librarian--ADA" />
				<asp:ListItem Value="Librarian--Business" Text="Librarian--Business" />
				<asp:ListItem Value="Librarian--Databases" Text="Librarian--Databases" />
				<asp:ListItem Value="Librarian--General" Text="Librarian--General" />
				<asp:ListItem Value="Librarian--Local History" Text="Librarian--Local History" />
				<asp:ListItem Value="Purchase Request" Text="Purchase Request" />
				<asp:ListItem Value="Webmaster" Text="Webmaster" />
			</asp:DropDownList>
					
	</form>				

									
					
<%


Dim strVariable as String

 
strVariable = who.SelectedItem.Value


	if strVariable = "Bookmobile"
	Response.Write("Bookmobile was selected")
	
	elseif strVariable = "Webmaster"
	Response.Write("<strong>Webmaster was selected</strong>")
	
	elseif strVariable = "Lending Services"
	Response.WriteFile("test.inc")


end if

%>	


Just to reiterate my problem (this one,a s opposed to the multitude of others I have, heh), "...contact.aspx?contact=Webmaster" works fine, but "...contact.aspx" results in a list that never posts back with the chosen list item, it just keeps going to the default.

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 5/5/2008 17:02:15   
quote:

<form method="post" action="contact.aspx" runat="server">


You have more than 1 form on that page? It's hard to tell since you aren't showing the whole page.

Typically an ASPX page *is* a form so you can't nest a form. In many cases (most for me anyways), a page will start something like this:

<body runat=server id="body1" >
<form id="frmCompany" runat="server">
...

so that's why I suspect nested forms. An ASPX page typically will do a lot of postbacks hence the whole page usually being 1 form. That's how I know the .NET environment typically to be.

I didn't design it so don't shoot the messenger...:)

Also, the way I'm seeing your page is that this code:

        If not (IsDBNull(contact)) Then
                who.SelectedItem.Selected = False
                For Each item As ListItem In who.Items
                    If item.Value = contact Then
                        item.Selected = True
                    End If
                Next
        End If


needs to be nested in a OnPageLoad sub routine and I always put them on a codebehind page. If your page was mypage.aspx then a codebehind page named mypage.aspx.vb might look something like this:

Partial Class mypage
    Inherits System.Web.UI.Page
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If not (IsDBNull(contact)) Then
                who.SelectedItem.Selected = False
                For Each item As ListItem In who.Items
                    If item.Value = contact Then
                        item.Selected = True
                    End If
                Next
        End If
    End Sub
End Class


Now I don't really want to send you down the "path of no return", but if you're using codebehinds and you're niot familiar with them, read up a little on them so that you understand Page Declarations (to use the codebehind) and stuff like that.

If you're *not* using codebehinds, try to make sure the code comes after the dropdown or it'll have no effect. At least I think...I only use codebehinds. :)

Hope it helps

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/5/2008 17:39:41   
Thanks--I'll give this another try tomorrow.

I only have the one form on my page. I tried taking the form tags out, but then I got an error stating that the ASP:Dropdown needs to be between form tags, so I guess I'd have to otherwise declare this with my ASP header? I haven't been using code-behinds; I took a look at it, and tried a few things at one point, but I couldn't get it to work for what i was doing so I stayed with the spaghetti code. I'll take another look though if you think it will help.

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 5/7/2008 9:17:38   
OK, so I checked out the page you sent me and for the way you have it setup, you need to use the code this way:

...
					<h1>Contact Us</h1>
	<form id="Form1" method="post" action="contact.aspx" runat="server">					
			<asp:DropDownList runat="server" id="who" AutoPostBack="true" EnableViewState="true">
				<asp:ListItem Value="Please Choose:" Text="--Please Choose:--" />
				<asp:ListItem Value="Bookmobile" Text="Bookmobile" />
				<asp:ListItem Value="Byram Shubert Library" Text="Byram Shubert Library" />
				<asp:ListItem Value="Cos Cob Library" Text="Cos Cob Library" />
				<asp:ListItem Value="Development Office" Text="Development Office" />
				<asp:ListItem Value="Lending Services" Text="Lending Services" />
				<asp:ListItem Value="Librarian--ADA" Text="Librarian--ADA" />
				<asp:ListItem Value="Librarian--Business" Text="Librarian--Business" />
				<asp:ListItem Value="Librarian--Databases" Text="Librarian--Databases" />
				<asp:ListItem Value="Librarian--General" Text="Librarian--General" />
				<asp:ListItem Value="Librarian--Local History" Text="Librarian--Local History" />
				<asp:ListItem Value="Purchase Request" Text="Purchase Request" />
				<asp:ListItem Value="Webmaster" Text="Webmaster" />
			</asp:DropDownList>
					
	</form>				
<%

Dim contact = Request.QueryString.Item("contact")

%>

<%
    If Trim(contact & "") > "" Then
        who.SelectedItem.Selected = False
        For Each item As ListItem In who.Items
            If item.Value = contact Then
                item.Selected = True
            End If
        Next
    End If
%>
...


Notice I used Trim(contact & "") instead of IsNull and that seemed to work best in your case.

This should work but I ididn't fully test it with all the specifics of your page; you had 2 references to some include files that you didn't send. However, I don't think they will affect it any.

Hope it helps.

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/7/2008 12:55:51   
That worked great! Where do I send the check?:)

Just so I can wrap my own brain around it, can you tell me how/why is the Trim command functioning for this, where the "Null" wasn't?

I have one other question for you. When the contact.aspx page comes up with no URL passing, changing options in the dropdown list works as normal, but when the page is accessed with URL passing, the information that list item is supposed to bring up does come up but the list item itself does not appear as selected in the dropdown list (the default item displays only, which isn't a huge issue). Also, from the URL-passing page, when a new dropdown list item is selected, nothing changes on the page, I assume because the URL is not changing and has the query string in it (and thus "refreshing" the page has no effect). If a user wants to select a different list item at this point, do you think I should provide a link (button) pointing them back to the regular "contact.aspx" page (and perhaps disguised as a "reset this page" button), or do you think my script should account for this?

Once again, I appreciate the help. I really don't mean to have to hit you with all these extra questions, but if you do have any suggestions for me they would be most welcome.

Regards,

-_Will

(in reply to rdouglass)
rdouglass

 

Posts: 9265
From: Biddeford, ME USA
Status: offline

 
RE: Postbacks without JavaScript? - 5/7/2008 13:04:38   
quote:

can you tell me how/why is the Trim command functioning for this, where the "Null" wasn't?


Nope, can't tell you specifically but I just habitually use trim(myValue & "") to check for Nulls *and* empty strings. It's a single check and we have to remember that an empty string is not a Null and vice versa so you do have to check for both in many cases.

quote:

When the contact.aspx page comes up with no URL passing,


You mean a querystring? What specifically are you passing in the querystring and what is it supposed to do other than select the item? I'm not clear about that. Maybe this isn't really working...:) How about an example querystring?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/7/2008 14:15:21   
Whoops, sorry, I think I'm mixing my lingo here. I definitely mean when I pass a querystring via URL. So, if I want "Webmaster" passed to the contact.aspx page, I'd have "...contact.aspx?contact=Webmaster". The "contact" string I'm passing is indeed getting passed to the contact.aspx page, and the relevant on-page info is coming up as my "if, elseif" statements have determined it should, but in the dropdown menu itself, the selection isn't changing to show the querystring that has been passed (it stays at the default), which isn't a big deal. But if I choose a different selection from that same page (where the querystring has already been passed via URL), I can't actually choose anything else because my script is overriding any new selections, so my best guess is that I should allow a user to "reset" the page so there is no more querystring which will allow them to then choose something different from the dropdown and have it actually not be overridden; a simple page refresh from the browser won't allow this because it refreshes with the querystring intact in the URL.

Is that any clearer, or am I still not helping...?

< Message edited by IronWill -- 5/7/2008 15:43:23 >

(in reply to rdouglass)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/12/2008 11:18:40   
I got this to behave! Just to recap, when I was using a querystring in the URL (i.e. ...contact.aspx?contact=Webmaster), the correct item was being selected from the drop-down list as per the code you gave me, but the actual list itself wasn't reflecting that selected item--it was showing the first default item of the list. Well, after some tinkering around, was able to make the list reflect the passed query! So when someone follows the "Webmaster" querystring URL, not only does the Webmaster content for the page come up as it should, but the drop-down list also appears with "Webmaster" showing as selected. A minor thing, sure, but it's helpful in making the page consistent with what has been pre-chosen...

So, the way I got it to work is by putting the Trim/if/then "select" code you gave me *before* the drop-down list, like so:

<%

Dim contact = Request.QueryString.Item("contact")

%>

<%
    If Trim(contact & "") > "" Then
        who.SelectedItem.Selected = False
        For Each item As ListItem In who.Items
            If item.Value = contact Then
                item.Selected = True
            End If
        Next
    End If
%>


		
					<h1>Contact Us</h1>
	<form id="ContactUsForm" method="post" action="contact.aspx" runat="server">					
			<asp:DropDownList runat="server" id="who" AutoPostBack="true" EnableViewState="true">
				<asp:ListItem Value="Please Choose:" Text="--Please Choose:--" />
				<asp:ListItem Value="Bookmobile" Text="Bookmobile" />
				<asp:ListItem Value="Lending Services" Text="Lending Services" />
				<asp:ListItem Value="Purchase Request" Text="Purchase Request" />
				<asp:ListItem Value="Webmaster" Text="Webmaster" />
			</asp:DropDownList>
					
	</form>				


					
<br />					
					
<%


Dim strVariable as String

'- To access the value portion 
strVariable = who.SelectedItem.Value


	if strVariable = "Bookmobile"
	Response.Write("Bookmobile was selected")
	
	elseif strVariable = "Purchase Request"
	Response.Write("<form method='post' action='../asp/sendmail3_cdo.asp'><div class='centered'><label id='Label1'><em class='important'>*</em> Your Name: </label><input name='sender' type='text' /><br /><br /><label id='Label2'><em class='important'>*</em> Your E-mail Address: </label><input name='mailfrom' type='text' /><br /><br /><label id='Label3'>Your Telephone Number: </label><input name='phone' type='text' /><br /><br /><label id='label4'>Are You a: </label><select name='status'><option>Library Card Holder</option><option>Publisher</option><option>Author</option><option>Vendor</option><option>Other</option></select><br /><br /><label id='Label5'>Have you checked our catalog?</label><br /><input name='check' type='radio' checked='checked' value='Yes' />Yes<input name='check' type='radio' value='No' />No<br /><br /><label id='Label6'>This item is in what language?</label><br /><input name='language' type='radio' checked='checked' value='English' />English<input name='language' type='radio' value='Spanish' />Spanish<input name='language' type='radio' value='Japanese' />Japanese<input name='language' type='radio' value='Other' />Other<br /><br /><label id='Label7'>This item is for what age level?</label><br /><input name='agelevel' type='radio' checked='checked' value='Adult' />Adult<input name='agelevel' type='radio' value='Teen' />Teen<input name='agelevel' type='radio' value='Children' />Children<br /><br /><label id='Label8'><em class='important'>*</em> Title: </label><input name='title' type='text' /><br /><br /><label id='Label9'>Author: </label><input name='author' type='text' /><br /><br /><label id='Label10'>Publisher: </label><input name='publisher' type='text' /><br /><br /><label id='Label11'>Publication Date: </label><input name='pubdate' type='text' /><br /><br /><label id='Label12'>ISBN: </label><input name='isbn' type='text' /><br /><br /><label id='Label13'>Format: </label><select name='format'><option>Book</option><option>Audiobook</option><option>Video/DVD</option><option>Music CD</option></select><br /><br /><label id='Label14'>Additional Information or Comments:<br /></label><textarea name='comments' cols='30' rows='5'></textarea><br /><input type='hidden' name='subject' id='subject' value='Library Purchase Request' /><input type='hidden' name='mailto' id='mailto' value='%suggestioncontact%' /><input type='hidden' name='redirect' id='redirect' value='http://www.greenwichlibrary.org/thanks2.asp' /><input name='html' type='hidden' id='html' value='yes' /><input name='template' type='hidden' id='template' value='../asp/htmlmail/purchaserequests.htm' /><input name='Submit1' type='submit' value='Send Your Suggestion' />  <input name='Reset1' type='reset' value='Reset This Form' /></div></form>")
	
	elseif strVariable = "Webmaster"
	Response.Write("<strong>Webmaster was selected</strong>")
	
	elseif strVariable = "Lending Services"
	Response.WriteFile("test.inc")


end if

%>


I apologize if you already mentioned this and it got by me somehow. It works great though! I can't thank you enough. Hopefully this code will help someone else.

I do have one last question about this: when someone follows a querystring URL to my contact.aspx page, everything works fine, except that if they then decide to pick a different item from the drop-down list, they just keep getting the same page (I assume because there's a query in the current URL that is overriding their new choice). Is there a way I can force a new selection from the form to also "reset" the page's URL to just "...contact.aspx" so that the new selection will work, like with some kind of if/then statement combined with the form (is that even possible)?

Thanks!

(in reply to rdouglass)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/12/2008 15:23:11   
How about if I use a "Replace" function to replace any instance of the URL with querystring in the "action" label to just the URL that I want? I've been Googling around, and from what I can tell there is no built-in way to have ASP.NET specify a different URL than whatever is current at the time in terms of posting back the form "action"...

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/12/2008 16:16:12   
Okay, I've got a "Replace" script in place, but it doesn't seem to do anything to the "action" label being generated server-side by ASP.NET. Really not sure where I'm going wrong here...
Here's my code, which is currently in the document <head>, though I also tried it right after the ASP form, with no visible difference:

<script runat="server" type="vb">
Dim strContactAction As String
function FixAction(strContactAction)
	FixAction = Replace(strContactAction,"<action='contact.aspx?' id='ContactUsForm'","action='ItWorked!' id='ContactUsForm'")
end function
</script>

(in reply to rdouglass)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/13/2008 10:43:20   
Anyone? Could the answer maybe be as simple as a "Replace" to change the "action="...contact.aspx?contact=Webmaster" to "action="...contact.aspx" on the page?

This is sooooooo close to working the way I need it to, and I'm going crazy trying to fix this one last thing, lol! :)

(in reply to rdouglass)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/21/2008 14:09:35   
*bump*

There must be someone out there who has run into this issue and resolved it... :)

I'm Googling around for answers, but there is nothing too obvious out there. I was thinking the "Replace" might work, but maybe "Regex" would work better? Is what I'm asking even possible? Can code on the page be changed as it is being posted back?

EDIT: okay, maybe I can put this another way: how can I clear the querystring (if one exists) between page loads so that AutoPostBack doesn't get hung up on the same variables?

< Message edited by IronWill -- 5/21/2008 16:07:34 >

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/22/2008 15:31:59   
Okay, now I've been trying to use "OnSelectedIndexChanged" in the asp:dropdown with a script block using a Response.Redirect for the selection based on the base URL and then the selected item's value... But I keep running into an "expected end of statement" error. Any tips on how I should be using OnSelectedIndexChanged?

(in reply to IronWill)
IronWill

 

Posts: 111
Joined: 3/8/2007
Status: offline

 
RE: Postbacks without JavaScript? - 5/22/2008 16:48:21   
I got it to work!!!



Here is the code (I figured out finally that I needed to use the "script" tag):



<script runat="server" type="text/vb">

Sub who_SelectedIndexChanged(sender As Object, e As EventArgs)
   Response.Redirect("contact.aspx?contact=" + who.SelectedValue)
End Sub
</script>


and

	<form id="ContactUsForm" method="post" action="contact.aspx" runat="server">					
			<asp:DropDownList runat="server" id="who" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="who_SelectedIndexChanged">
				<asp:ListItem Value="General Information" Text="General Information" />
				<asp:ListItem Value="Bookmobile" Text="Bookmobile" />




However, there appears to be one small glitch... When I try to select the very first item on my list, it won't actually load. All the other items on the list work fine, just not the first one. Any thoughts? It loaded fine on its own before the script, so I know the syntax, etc, is okay as far as the dropdown form is concerned...

(in reply to rdouglass)
Page:   [1]

All Forums >> Web Development >> General Web Development >> Postbacks without JavaScript?
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts