c# - Multiple identical forms on a page in asp.net. How do I get variables? -
i'm having trouble figuring out. can't explain well, here html/asp first:
<%for(int i=0; i<getcountrows(); i++) { setlabelsfestivals(i); %> <form action="festival_details.aspx" method="post"> <table id="table_600px_border"> <tbody class="content_table_left" style='padding: 10px;'> <tr> <td class="content_table_300px content_table_left_up"> <div class="text_bold"> <asp:label id="namefestival" runat="server"></asp:label> </div> <asp:hiddenfield id="fest_id" runat="server" /> </td> <td class="content_table_300px content_table_left_up_bottom"> <asp:label id="startdatefestival" runat="server"></asp:label> </td> </tr> <tr> <td class="content_table_left_up"> <asp:label id="locationfestival" runat="server"></asp:label> </td> <td class="content_table_left_up"> <asp:label id="enddatefestival" runat="server"></asp:label> </td> </tr> <tr> <td class="content_table_left_up_bottom"> <asp:hyperlink id="urlfestival" runat="server">site</asp:hyperlink> </td> <td class="content_table_right_bottom"> <input type="submit" name="btndetails" value="details" /> </td> </tr> </tbody> </table> </form> <% }
for each row in dataset, form dynamically created simple submit button. happens in code behind
//this method makes sure correct labels shown on screen protected void setlabelsfestivals(int positiondataset) { //checking if data found bands if (getcountrows() > 0) { datetime dtstartdate = convert.todatetime(datasetfestivals.tables[0].rows[positiondataset]["fest_datum"].tostring()); datetime dtenddate = convert.todatetime(datasetfestivals.tables[0].rows[positiondataset]["fest_einddatum"].tostring()); //showing festivals , data namefestival.text = datasetfestivals.tables[0].rows[positiondataset]["fest_naam"].tostring(); fest_id.value = datasetfestivals.tables[0].rows[positiondataset]["fest_id"].tostring(); startdatefestival.text = "begindatum: " + dtstartdate.tostring("yyyy-mm-dd"); locationfestival.text = "locatie: " + datasetfestivals.tables[0].rows[positiondataset]["fest_locatie"].tostring(); enddatefestival.text = "einddatum: " + dtenddate.tostring("yyyy-mm-dd"); urlfestival.navigateurl = "http://" + datasetfestivals.tables[0].rows[positiondataset]["fest_url"].tostring(); urlfestival.target = "_blank"; } }
so, how can example value of hidden field width id "fest_id" in festival_details.aspx? tried:
httpcontext variables = httpcontext.current; strformidfest = variables.request["fest_id"];
however, string strformidfest null. guess it's got clientid?
first off, asp.net webforms designed use 1 form per page. should consider using control repeater render your controls within same form.
anyhow. if looking (using breakpoint , quick watch) @ request variables should able find hidden field. not named "fest_id", got name containing page , control name , bunch of other characters. default way asp.net controls (like asp:hiddenfield).
you may force asp.net give control id if using asp.net 4.0 setting clientidmode static:
<asp:hiddenfield id="fest_id" runat="server" clientidmode="static" />
or may use standard html hidden control correct id cannot use code behind set value in case:
<input type="hidden" name="fest_id" id="fest_id">
you should consider if loop in aspx way go. not standard way go in webforms. take @ repeater or control render complex markup.
Comments
Post a Comment