Getting hidden field value on next page

Ice

Member
Joined
Jan 25, 2013
Messages
14
Programming Experience
Beginner
Hi

I have a hidden value field on a page. On submit I post to a different page. On the page I've posted to I do a Request.Form but I do not get the value just a null value.

This is the initial page
C#:
<div id="booking_content_wrapper">
        <form id="mainForm" name="mainForm" runat="server" action="Cancellation.aspx">
            <h2>Paid Bookings</h2>
            <table cellpadding="0" cellspacing="0" border="0" id="booking_table">
                <tr>
                    <th width="110">Enquiry No.</th>
                    <th width="250">Establishment</th>
                    <th width="110">Arrival Date</th>
                    <th width="20">Confirmed</th>
                    <th>Action</th>
                </tr>
        
                 <asp:Literal ID="PaidBookingsResults" runat="server"></asp:Literal>
            </table>        
            <asp:HiddenField runat="server" ID="ResID" EnableViewState="true" />
        </form>
    </div>
<script>
    function ViewCancellation(sResID) {
        document.getElementById("<%=ResID.ClientID%>").value = sResID;
        document.getElementById("mainForm").submit();
    }

</script>

The javascript ViewCancellation function is set to a hyperlink in the code behind. The function will have a value like this,<a href=\"#\" onclick=\"ViewCancellation(54666);return false;\">cancel</a>

On the page I'm posting to I'm doing this

C#:
string sResID = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext context = HttpContext.Current;
        sResID = context.Request.Form["ResID"] != null ? context.Request.Form["ResID"] : "";
        sResID = Regex.Replace(sResID, "/[^A-Z]\\d-/g", "");

        context.Response.Write(sResID);

    }

sResID gets no value because context.Request.Form["ResID"] is null. How can I get the value to this page. I have enabledviewstate
 
I just performed a repro using what you posted here, added the anchor with onclick ViewCancellation call manually, and I do get string 54666 displayed in Cancellation.aspx page. Not sure why this doesn't work for you too.
 
Please could you post the code. You might be doing something small that I'm overlooking.
I am using master pages as well, if that's of any consequence?
 
Please could you post the code. You might be doing something small that I'm overlooking.
I am using master pages as well, if that's of any consequence?
I'm not doing anything, I just copy/paste from your post into two new pages.
 
Hi

I've fixed it by using a normal input instead of an asp hiddenfield and then changed the
querystring to this

protected void Page_Load(object sender, EventArgs e)
{
String sdata = !String.IsNullOrEmpty(Request["data"]) ? Request["data"] : "";
Data.Text = sdata;
}
 
Back
Top Bottom