Reputation: 5876
I have an html form with hidden values empty like below
<body>
<form runat="server" id="PostToMPI" name="PostToMPI" method="post" action="https://www.e-tahsildar.com.tr/V2/NetProvOrtakOdeme/NetProvPost.aspx" >
<asp:HiddenField ID="pHashB64" runat="server" Value="" />
<asp:HiddenField ID="pHashHex" runat="server" Value="" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
in the c#
protected void Button1_Click(object sender, EventArgs e)
{
pHashB64.Value = "calculated value";
pHashHex.Value = "calculated value";
}
it is using post method. when the user clicks the button, I am calculating the values set them to the hidden fields.
I am wondering if it submits the form before it sets the hidden fields? I mean that I am posting with empty fields?
thank you
Upvotes: 0
Views: 711
Reputation: 2587
When you specify action attribute in form tag, it transfers your request to that URL instead of firing postback in the same page and executing button click event.
Rather you can use querystring method whose URL will be generated in button click event and redirecting to the URL set in action attribute.
<form runat="server" id="PostToMPI" name="PostToMPI" method="post" >
<asp:HiddenField ID="pHashB64" runat="server" Value="" />
<asp:HiddenField ID="pHashHex" runat="server" Value="" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
Upvotes: 1