0

On the Page_Load of my action page, I'm getting the form variables like this
string name = HttpContext.Current.Request.Form["Name"];

I then have two functions that use these variables. In the first function, I'm inserting the values into a database and get an error that the procedure expects a parameter that wasn't supplied. The second function that calls a webservice works perfectly with these same variables. I've checked the stored procedure and everything looks fine there.

I've enabled tracing and these variables are displaying a blank value, but it is somehow working for that second function.

There's also a cms involved. The form is actually on a different aspx page than what it's posting to.

Any ideas what might be wrong?

2
Contributors
5
Replies
13
Views
3 Years
Discussion Span
Last Post by JorgeM
0

Are you saying that HttpContext.Current.Request.Form["Name"] doesnt not contain a value?

Are you sure that you are sending the values to that page using POST? but then you say the webservice works so the variable "Name" does have a value?

Since your inserting into the db process is not working, its likely the problem is there. Do you have sample code?

0
protected void Page_Load(object sender, EventArgs e)
{
        string sal = HttpContext.Current.Request.Form["Salutation"];
        string name = HttpContext.Current.Request.Form["Name"];
        string desig = HttpContext.Current.Request.Form["designation"];
        string institution = HttpContext.Current.Request.Form["Institution_"];
        string email = HttpContext.Current.Request.Form["Email_address_"];
        bool emailUpdates = Convert.ToBoolean(HttpContext.Current.Request.Form["EmailUpdates_"]);
        bool permission = Convert.ToBoolean(HttpContext.Current.Request.Form["Permission"]);

        //testing:
        //titleLabel.Text = sal;
        //nameLabel.Text = name;
        //desigLabel.Text = desig;
        //institutionLabel.Text = institution;
        //emailLabel.Text = email;
        //updatesLabel.Text = emailUpdates.ToString();
        //permissionLabel.Text = permission.ToString();

        StoreInDB(sal, name, desig, institution, email, emailUpdates, permission);

        //call webservice to send email
        bool success = SendEmail(sal, name, desig, email);
}

private void StoreInDB(string title, string name, string designation, string institution, string email, bool updates, bool permission)
 {
        try
        {
            using (SqlConnection connection = new SqlConnection(pledgeDBconnection))
            {
                connection.Open();

                SqlCommand insertPledge = new SqlCommand("insertPledge", connection);
                insertPledge.CommandType = CommandType.StoredProcedure;
                insertPledge.Parameters.AddWithValue("@title", title);
                insertPledge.Parameters.AddWithValue("@name", name);
                insertPledge.Parameters.AddWithValue("@designation", designation);
                insertPledge.Parameters.AddWithValue("@institution", institution);
                insertPledge.Parameters.AddWithValue("@email", email);
                insertPledge.Parameters.AddWithValue("@updates", updates);
                insertPledge.Parameters.AddWithValue("@permission", permission);

                insertPledge.ExecuteNonQuery();

                connection.Close();
            }
        }
        catch (Exception ex)
        {
            Trace.Warn(DateTime.Now.ToString(), ex.ToString());
        }
}

Stored Procedure:
ALTER PROCEDURE [dbo].[insertPledge]
(
    @title          NVARCHAR(50),
    @name           NVARCHAR(50),
    @designation    NVARCHAR(50),
    @institution    NVARCHAR(50),
    @email          NVARCHAR(50),
    @updates        bit,
    @permission     bit
)
AS
BEGIN
    INSERT INTO pledges(title, name, designation, institution, email, email_updates, permission, date_submitted)
    VALUES (@title, @name, @designation, @institution, @email, @updates, @permission, CURRENT_TIMESTAMP)
END

The labels on the page are all empty and when I put in Trace statements, the variables are all blank. Well, actually, the 2 radio buttons always display as false.

The SendEmail function works fine though. I put Trace statements in that function as well, and the variables are displaying empty there too, but it somehow is still getting the data and works.

0

Have you used your browser's dev tools (hit f12) to inspect the headers? You will be able to see there whether or not the parameters are actually being passed via POST. here is a screen clip of what i just described using Chrome. You can see that the data was sent via POST. Dont pay attention to the parameter names...its just an example i grabbed off some site.

72e458a4017c9cbcf658a45e21af1013

Edited by JorgeM

0

Thanks for the tip! I've made some progress.
Apparently the form data is working on the live site but not the dev site, so I've been comparing.

Upon form submittal, the working site's page has a 200 status while the non-working site's page has a 302 status and redirection. See screenshots. I can't figure out what's causing this difference.

edit: those screenshots are tiny. I'm not sure how to fix that, but if you click on each, they'll get bigger.

Edited by yssirhc

Attachments form_submittal_working.png 7.53 KB form_submittal_not_working.png 14.21 KB
0

Did you check your config file? maybe you have URL rewrite/redirect rules there?

If not, the redirect will be in your code-behind on the radiologycaressubmittal.aspx.cs page (if infact you have two pages).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.