Link to home
Start Free TrialLog in
Avatar of thedeal56
thedeal56

asked on

ASP.NET Post Data

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
Avatar of vbwizardry
vbwizardry
Flag of United States of America image

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.
Avatar of thedeal56
thedeal56

ASKER

Is there a way to send data in a post style without using a form? Like something I could do programmatic-ally?  
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

is that a way around the two form ordeal?
as long as you are not trying to add another form above should work.
Question:
Why don't you set form in your MasterPage2 to use post method by default? Why did you change it to get?
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

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.
also you would have to change
asp:QueryStringParameter to asp:FormParameter in taxrecords.aspx
Good deal.  I'll look in to this tonight.  I really appreciate you helping me on this.
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.

ASKER CERTIFIED SOLUTION
Avatar of vbwizardry
vbwizardry
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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'.
do not add [runat="server"] simply use
<input type="text" name="billnumber" />

Open in new window

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?
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

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

sorry for the double code snippets.  I just meant to post one.
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.
Awesome!