I am creating an intelligent questionnaire with VWD 2008 GridView. I am using the RadioButtonList and the values (5, 4, 3, 2, 1) are stored as cookie. For Q1, when I c;lick Button3, I want to proceed to Q2 if the value selected is 5, else I should proceed
to Q3. How can I modify my code for the cookie to do this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
//Write cookie directly to collection.
Response.Cookies["Q1"].Value = Label2.Text.ToString();
//Read a cookie value directly, encoding it for safety.
if (Request.Cookies["Q1"] != null)
{
Label2.Text = Server.HtmlEncode(Request.Cookies["Q1"].Value);
Response.Redirect("../QuestLocal/Q2.aspx");
}
}
}
Your understanding is correct except that I am getting the error below. Note that I use the RadioButtonList in the template.
Server Error in '/QuestLocal' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'RadioButtonList1' does not exist in the current context
Source Error:
Line 15: {
Line 16: //Read a cookie value directly, encoding it for safety.
Line 17: if (Request.Cookies["Q1"] != null && RadioButtonList1.SelectedValue.Equals("5"))
Line 18: {
Line 19: Response.Cookies["Q1"].Value = Label2.Text.ToString();
Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 17
Just a couple of error messages below to fix. I would be very grateful.
Server Error in '/QuestLocal' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'j' does not exist in the current context
Source Error:
Line 19: {
Line 20: RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("radioButtonListID")));
Line 21: for (j = 0; (j <= rbl.Items.Count); j++)
Line 22: {
Line 23: if ((rbl.Items(j).Value == "5"))
Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 21
Server Error in '/QuestLocal' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1955: Non-invocable member 'System.Web.UI.WebControls.ListControl.Items' cannot be used like a method.
Source Error:
Line 21: for (int j = 0; (j <= rbl.Items.Count); j++)
Line 22: {
Line 23: if ((rbl.Items(j).Value == "5"))
Line 24: {
Line 25: if (Request.Cookies["q1"] != null)
Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 23
asante_za
Member
16 Points
113 Posts
Condition in Cookie
Apr 21, 2012 10:31 AM|LINK
Hi
I am creating an intelligent questionnaire with VWD 2008 GridView. I am using the RadioButtonList and the values (5, 4, 3, 2, 1) are stored as cookie. For Q1, when I c;lick Button3, I want to proceed to Q2 if the value selected is 5, else I should proceed to Q3. How can I modify my code for the cookie to do this?
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { //Write cookie directly to collection. Response.Cookies["Q1"].Value = Label2.Text.ToString(); //Read a cookie value directly, encoding it for safety. if (Request.Cookies["Q1"] != null) { Label2.Text = Server.HtmlEncode(Request.Cookies["Q1"].Value); Response.Redirect("../QuestLocal/Q2.aspx"); } } }Peter pi - M...
Star
12871 Points
1786 Posts
Re: Condition in Cookie
Apr 24, 2012 02:24 AM|LINK
I don't fully understand what is the meaning of the following sentence? Could you describe it in details?
protected void Button3_Click(object sender, EventArgs e) { //Read a cookie value directly, encoding it for safety. if (Request.Cookies["Q1"] != null && RadioButtonList1.SelectedValue.Equals("5")) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } else { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 24, 2012 05:35 AM|LINK
Hi
Your understanding is correct except that I am getting the error below. Note that I use the RadioButtonList in the template.
Server Error in '/QuestLocal' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'RadioButtonList1' does not exist in the current context Source Error: Line 15: { Line 16: //Read a cookie value directly, encoding it for safety. Line 17: if (Request.Cookies["Q1"] != null && RadioButtonList1.SelectedValue.Equals("5")) Line 18: { Line 19: Response.Cookies["Q1"].Value = Label2.Text.ToString(); Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 17AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 24, 2012 07:43 AM|LINK
first of all since your radiobuttonlist in your gridview you need to get it from there so in you button on click event do the following
foreach (GridViewRow gvr in GridView1.Rows) { if ((gvr.RowType == DataControlRowType.DataRow)) { RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("radioButtonListID"))); for (j = 0; (j <= rbl.Items.Count); j++) { if ((rbl.Items(j).Value == "5")) { if (Request.Cookies["q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } else { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } } } } }asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 24, 2012 06:34 PM|LINK
Just a couple of error messages below to fix. I would be very grateful.
Server Error in '/QuestLocal' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'j' does not exist in the current context Source Error: Line 19: { Line 20: RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("radioButtonListID"))); Line 21: for (j = 0; (j <= rbl.Items.Count); j++) Line 22: { Line 23: if ((rbl.Items(j).Value == "5")) Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 21AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 24, 2012 06:37 PM|LINK
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 24, 2012 06:53 PM|LINK
intj is still red underlined as error.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 24, 2012 06:57 PM|LINK
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 24, 2012 07:05 PM|LINK
Server Error in '/QuestLocal' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1955: Non-invocable member 'System.Web.UI.WebControls.ListControl.Items' cannot be used like a method. Source Error: Line 21: for (int j = 0; (j <= rbl.Items.Count); j++) Line 22: { Line 23: if ((rbl.Items(j).Value == "5")) Line 24: { Line 25: if (Request.Cookies["q1"] != null) Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 23Peter pi - M...
Star
12871 Points
1786 Posts
Re: Condition in Cookie
Apr 25, 2012 12:58 AM|LINK
Beacuse the Items is a property, it does not a method, so you need to use as follows:
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework