Solved

ASP.NET Post Data

Posted on 2011-03-01
22
500 Views
Last Modified: 2012-05-11
I have a feeling that I am not going to be able to explain myself very well on this issue.  Please forgive my .net ignorance. A few years ago, I created an interface for a database of tax records.  Here's the link to this interface:
http://www.murfreesborotn.gov/search.aspx

Please use the search so you'll be familiar with the pages I'll refer to later in this post.

The two pages I'm concerned with in this question are search.aspx and taxrecords.aspx.  I will need help with totals.aspx too, but I would like to split that into a different post.  

When you use the search, you'll notice that I passed all of my variables through the URL.  This worked well for a while, but now I have a need to pass my information in a "POST" like method.  Pretty much, I need to remove the variable info from the URL, but I still need to pass it from page to page.  

I tried to accomplish this using the html method of:

<form runat=server method=post action=taxrecords.aspx>

I know that method would work on a "normal" site, but we use Ektron as our CMS, and i get an error message about the page having two forms when I use it.  

I have attached the two pages I've mentioned.  How would I go about converting these pages to use POST instead of the method that I'm using now?  Thanks for reading.  Please let me know if I need to explain myself any further.  


search.aspx
taxrecords.aspx
0
Comment
Question by:thedeal56
  • 13
  • 9
22 Comments
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
are you changing form method in your master page or do you add a new form. If you are adding a new form you cant do that. Multiple server forms are not supported by regular asp.net.
0
 

Author Comment

by:thedeal56
Comment Utility
Is there a way to send data in a post style without using a form? Like something I could do programmatic-ally?  
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
yes...kind of...
You can, in your search.aspx load event handler, set form method to post as in.
        protected void Page_Load(object sender, EventArgs e)
        {
            Form.Method = "post";
        }

Open in new window

0
 

Author Comment

by:thedeal56
Comment Utility
is that a way around the two form ordeal?
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
yes
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
as long as you are not trying to add another form above should work.
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
Question:
Why don't you set form in your MasterPage2 to use post method by default? Why did you change it to get?
0
 

Author Comment

by:thedeal56
Comment Utility
Well, the master form was set to get by the content manager, Ektron.  On the pages that i'm talking about in this post, there was never a real form tag that was handling any of the data transfer.  I was just using a redirect in VB.net like this:
Protected Sub test_click(ByVal sender As Object, ByVal e As ImageClickEventArgs) Handles test.Click

                Response.Redirect("taxrecords.aspx?ekmenu=112&name=" + name.Text + "&address=" + address.Text + "&ctlmap=" + ctlmap.Text + "&group=" + group.Text + "&parcel=" + parcel.Text + "&propid=" + propid.Text + "&specint=" + specint.Text + "&billyear=" + billyear.Text + "&billnumber=" + billnumber.Text + "&Account=" + Account.Text )

            End Sub

Open in new window

0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
the form tag most likely located in MasterPage2. If you are using a Response.Redirect you might as well use html tags instead of asp control's. Also in page load event you can set the location of the form post/get method. That way you will not need to redirect. Look at HtmlForm class. You can set Action, Method and Target on the form.
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
also you would have to change
asp:QueryStringParameter to asp:FormParameter in taxrecords.aspx
0
 

Author Comment

by:thedeal56
Comment Utility
Good deal.  I'll look in to this tonight.  I really appreciate you helping me on this.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:thedeal56
Comment Utility
I had a chance to look at this last night, but I'm still unclear on how to make this work.  Here are the steps I took.

Remove the test_click Sub
Created a form with post method on search.aspx but did not add runat=server
Changed my image button info a form submit button
Changed asp:QueryStringParameter to asp:FormParameter in taxrecords.aspx

When I did this, the form never actually submitted to the taxrecords.aspx page.  Instead, the page flashed and stayed on search.aspx.

0
 
LVL 7

Accepted Solution

by:
vbwizardry earned 500 total points
Comment Utility
Remove the test_click Sub
add this to the page
<script runat="server">
	Sub Page_Load
		if Not Page.IsPostBack then
			Form.Method = "post"
			Form.Action = "taxrecords.aspx"
		end if
	End Sub
</script>

Open in new window


Change asp:TextBox to regular html control [http://www.w3schools.com/html/html_forms.asp]

Do not created form with post method on search.aspx

Changed my image button info a form submit button [you don't have to do it]

Changed asp:QueryStringParameter to asp:FormParameter in taxrecords.aspx

0
 

Author Comment

by:thedeal56
Comment Utility
Ah, I'm starting to see what you're saying now.  When you say to change the textbox to a regular html control, this is what you mean, right?

Take this:
 <asp:TextBox runat="server" ID="billnumber" size="8" maxlength=10 TextMode="SingleLine"></asp:TextBox>

Change to this:
<input runat="server" name="billnumber" size="8" maxlength=10></input>

Also, When I added the script from your prior post, I came across this error message:
BC30456: 'Action' is not a member of 'System.Web.UI.HtmlControls.HtmlForm'.
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
do not add [runat="server"] simply use
<input type="text" name="billnumber" />

Open in new window

0
 

Author Comment

by:thedeal56
Comment Utility
Good deal.  Will that take care of this too?
BC30456: 'Action' is not a member of 'System.Web.UI.HtmlControls.HtmlForm'.

I saw somewhere that this was a .net version issue.  Have you ever ran across that error?
0
 

Author Comment

by:thedeal56
Comment Utility
I got .net 3.5 SP1, and that fixed the BC30456 error.  Now I am getting a sql timeout error when I submit the form.  Do I need to change anything else in this section?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProptaxConnectionString %>"
            SelectCommand="sp_TaxRec" CancelSelectOnNullParameter="False" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:FormParameter Name="name1" QueryStringField="name" ConvertEmptyStringToNull="False" />
                <asp:FormParameter ConvertEmptyStringToNull="False" Name="property_add" QueryStringField="address" />
                <asp:FormParameter Name="ctlmap" QueryStringField="ctlmap" />
                <asp:FormParameter Name="bill_group" QueryStringField="group" />
                <asp:FormParameter Name="bill_parcel" QueryStringField="parcel" />
                <asp:FormParameter Name="propertyid" QueryStringField="propid" />
                <asp:FormParameter Name="special" QueryStringField="specint" />
                <asp:FormParameter Name="bill_year" QueryStringField="billyear" />
                <asp:FormParameter Name="bill_no" QueryStringField="billnumber" />
                <asp:FormParameter Name="account" QueryStringField="account" />
            </SelectParameters>
        </asp:SqlDataSource>

Open in new window

0
 

Author Comment

by:thedeal56
Comment Utility
I made a slight change to this, but it's still timing out
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProptaxConnectionString %>"
            SelectCommand="sp_TaxRec" CancelSelectOnNullParameter="False" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:FormParameter Name="name1" FormField="name" ConvertEmptyStringToNull="False" />
                <asp:FormParameter ConvertEmptyStringToNull="False" Name="property_add" FormField="address" />
                <asp:FormParameter Name="ctlmap" FormField="ctlmap" />
                <asp:FormParameter Name="bill_group" FormField="group" />
                <asp:FormParameter Name="bill_parcel" FormField="parcel" />
                <asp:FormParameter Name="propertyid" FormField="propid" />
                <asp:FormParameter Name="special" FormField="specint" />
                <asp:FormParameter Name="bill_year" FormField="billyear" />
                <asp:FormParameter Name="bill_no" FormField="billnumber" />
                <asp:FormParameter Name="account" FormField="account" />
            </SelectParameters>
        </asp:SqlDataSource>

Open in new window

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProptaxConnectionString %>"
            SelectCommand="sp_TaxRec" CancelSelectOnNullParameter="False" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:FormParameter Name="name1" FormField="name" ConvertEmptyStringToNull="False" />
                <asp:FormParameter ConvertEmptyStringToNull="False" Name="property_add" FormField="address" />
                <asp:FormParameter Name="ctlmap" FormField="ctlmap" />
                <asp:FormParameter Name="bill_group" FormField="group" />
                <asp:FormParameter Name="bill_parcel" FormField="parcel" />
                <asp:FormParameter Name="propertyid" FormField="propid" />
                <asp:FormParameter Name="special" FormField="specint" />
                <asp:FormParameter Name="bill_year" FormField="billyear" />
                <asp:FormParameter Name="bill_no" FormField="billnumber" />
                <asp:FormParameter Name="account" FormField="account" />
            </SelectParameters>
        </asp:SqlDataSource>

Open in new window

0
 

Author Comment

by:thedeal56
Comment Utility
sorry for the double code snippets.  I just meant to post one.
0
 

Author Comment

by:thedeal56
Comment Utility
ok, nevermind all that.  It looks to be working now! Thanks again for all your help.  I still need help posting from taxrecords.aspx in to totals.aspx.  I'll make a new question, and I'll post back here when I do.
0
 

Author Closing Comment

by:thedeal56
Comment Utility
Awesome!
0
 

Author Comment

by:thedeal56
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now