Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 29, 2009 09:11 AM by mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
May 28, 2009 09:17 AM|LINK
Since you are inserting on button click and using on page load you need to put it in if condition to check if it has items in it
if(arr.Count > 0)
{
ddlTitle.Text = arr[0].ToString(); txtFName.Text = arr[1].ToString(); txtLName.Text = arr[2].ToString(); txtDesignation.Text = arr[3].ToString(); txtEmail.Text = arr[4].ToString(); txtFaxno.Text = arr[5].ToString(); txtMobileNo.Text = arr[6].ToString(); txtPin.Text = arr[7].ToString(); txtPhone.Text = arr[8].ToString();
}
Participant
1182 Points
1697 Posts
May 28, 2009 09:34 AM|LINK
This is working....code
on Click
Session["title"] = ddlTitle.SelectedItem.Text; Session["fname"] = txtFName.Text; Session["lname"] = txtLName.Text; Session["sex"] = RadioButtonList1.SelectedItem.Text; Session["designation"] = txtDesignation.Text; Session["pin"] = txtPin.Text; Session["email"] = txtEmail.Text; Session["mobile"] = txtMobileNo.Text; Session["phone"] = txtPhone.Text; Session["fax"] = txtFaxno.Text;
on page load
ddlTitle.Text = Session["title"].ToString(); txtFName.Text = Session["fname"].ToString(); txtLName.Text = Session["lname"].ToString(); txtDesignation.Text = Session["designation"].ToString(); txtEmail.Text = Session["email"].ToString(); txtFaxno.Text = Session["fax"].ToString(); txtMobileNo.Text = Session["mobile"].ToString(); txtPin.Text = Session["pin"].ToString(); txtPhone.Text = Session["phone"].ToString();
How can I apply check condition on this like you have done in following(arr.Count>0).
I need to check each control weither its having value or blank.
But this is erring...
Button Click
arr.Add(txtDesignation.Text); arr.Add(ddlTitle.SelectedItem.Text); arr.Add(txtFName.Text); arr.Add(txtLName.Text); arr.Add(RadioButtonList1.SelectedItem.Text); arr.Add(txtPin.Text); arr.Add(txtEmail.Text); arr.Add(txtMobileNo.Text); arr.Add(txtPhone.Text); arr.Add(txtFaxno.Text);
if(arr.count>0)
if (arr.Count > 0) { txtFName.Text = arr[1].ToString(); txtLName.Text = arr[2].ToString(); txtDesignation.Text = arr[3].ToString(); txtEmail.Text = arr[4].ToString(); txtFaxno.Text = arr[5].ToString(); txtMobileNo.Text = arr[6].ToString(); txtPin.Text = arr[7].ToString(); txtPhone.Text = arr[8].ToString(); }
thanx for your support..[:)]
May 28, 2009 10:07 AM|LINK
If that many items are there I'll suggest not to use arrays as it will make it more complex if you had more than 20 items to store I would have used arrays but using normal session makes code more readable
To apply consition just do this way in page load
ArrayList arr = (ArrayList)Session["arr"];
if (arr!=null && arr.Count > 0) { txtFName.Text = arr[1].ToString(); txtLName.Text = arr[2].ToString(); txtDesignation.Text = arr[3].ToString(); txtEmail.Text = arr[4].ToString(); txtFaxno.Text = arr[5].ToString(); txtMobileNo.Text = arr[6].ToString(); txtPin.Text = arr[7].ToString(); txtPhone.Text = arr[8].ToString(); }
Also this is correct
May 28, 2009 10:34 AM|LINK
There is no error but the filled control become blank...like control txtLName.Text doent have value which i filled before.....?
thanx for ur continuous support ..:)
May 28, 2009 11:00 AM|LINK
I'll suggest follow the previous method that you used
May 28, 2009 11:03 AM|LINK
demoninside9 arr.Add(txtDesignation.Text); arr.Add(ddlTitle.SelectedItem.Text); arr.Add(txtFName.Text); arr.Add(txtLName.Text); arr.Add(RadioButtonList1.SelectedItem.Text); arr.Add(txtPin.Text); arr.Add(txtEmail.Text); arr.Add(txtMobileNo.Text); arr.Add(txtPhone.Text); arr.Add(txtFaxno.Text);
First code was working reason you saved in session and then getting it Now in case of arrays you are not saving it in session'
Session["arr"] = arr;
May 28, 2009 11:15 AM|LINK
Still it shows
Object reference not set to an instance of an object.
on first line of this code
arr.Add(txtDesignation.Text); // here it shows error arr.Add(ddlTitle.SelectedItem.Text); arr.Add(txtFName.Text); arr.Add(txtLName.Text); arr.Add(RadioButtonList1.SelectedItem.Text); arr.Add(txtPin.Text); arr.Add(txtEmail.Text); arr.Add(txtMobileNo.Text); arr.Add(txtPhone.Text); arr.Add(txtFaxno.Text);
May 28, 2009 11:24 AM|LINK
i am not having much knowledge about arrays.
for this time i shld go for sessions method which i used previous.
thank u very much dear. [:)]
May 28, 2009 11:30 AM|LINK
If you are new make things simple once you got it working start refining you can always post your code on forums and ask people to suggest
But yes if you make that correction I think it will work
May 29, 2009 04:44 AM|LINK
Hi...
Now i have written
on button click
ArrayList arr=new ArrayList(); protected void btnOrg_Click1(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtDesignation.Text)) { arr.Add(txtDesignation.Text); } else if (!String.IsNullOrEmpty(ddlTitle.SelectedItem.Text)) { arr.Add(ddlTitle.SelectedItem.Text); } else if (!String.IsNullOrEmpty(txtFName.Text)) { arr.Add(txtFName.Text); } else if (!String.IsNullOrEmpty(txtLName.Text)) { arr.Add(txtLName.Text); } else if (!String.IsNullOrEmpty(txtPin.Text)) { arr.Add(txtPin.Text); } else if (!String.IsNullOrEmpty(txtEmail.Text)) { arr.Add(txtEmail.Text); } else if (!String.IsNullOrEmpty(txtMobileNo.Text)) { arr.Add(txtMobileNo.Text); } else if (!String.IsNullOrEmpty(txtPhone.Text)) { arr.Add(txtFaxno.Text); } else { } Session["arr"] = arr;
And on page load
On Page_Load()
ArrayList arr = (ArrayList)Session["arr"]; if (arr != null && arr.Count > 0) { txtFName.Text = arr[1].ToString(); txtLName.Text = arr[2].ToString(); txtDesignation.Text = arr[3].ToString(); txtEmail.Text = arr[4].ToString(); txtFaxno.Text = arr[5].ToString(); txtMobileNo.Text = arr[6].ToString(); txtPin.Text = arr[7].ToString(); txtPhone.Text = arr[8].ToString(); }
it still shows error
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
thanx
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to move value from one form to another
May 28, 2009 09:17 AM|LINK
Since you are inserting on button click and using on page load you need to put it in if condition to check if it has items in it
if(arr.Count > 0)
{
ddlTitle.Text = arr[0].ToString();
txtFName.Text = arr[1].ToString();
txtLName.Text = arr[2].ToString();
txtDesignation.Text = arr[3].ToString();
txtEmail.Text = arr[4].ToString();
txtFaxno.Text = arr[5].ToString();
txtMobileNo.Text = arr[6].ToString();
txtPin.Text = arr[7].ToString();
txtPhone.Text = arr[8].ToString();
}
Contact me
demoninside9
Participant
1182 Points
1697 Posts
Re: How to move value from one form to another
May 28, 2009 09:34 AM|LINK
This is working....code
on Click
Session["title"] = ddlTitle.SelectedItem.Text;
Session["fname"] = txtFName.Text;
Session["lname"] = txtLName.Text;
Session["sex"] = RadioButtonList1.SelectedItem.Text;
Session["designation"] = txtDesignation.Text;
Session["pin"] = txtPin.Text;
Session["email"] = txtEmail.Text;
Session["mobile"] = txtMobileNo.Text;
Session["phone"] = txtPhone.Text;
Session["fax"] = txtFaxno.Text;
on page load
ddlTitle.Text = Session["title"].ToString();
txtFName.Text = Session["fname"].ToString();
txtLName.Text = Session["lname"].ToString();
txtDesignation.Text = Session["designation"].ToString();
txtEmail.Text = Session["email"].ToString();
txtFaxno.Text = Session["fax"].ToString();
txtMobileNo.Text = Session["mobile"].ToString();
txtPin.Text = Session["pin"].ToString();
txtPhone.Text = Session["phone"].ToString();
How can I apply check condition on this like you have done in following(arr.Count>0).
I need to check each control weither its having value or blank.
But this is erring...
Button Click
arr.Add(txtDesignation.Text);
arr.Add(ddlTitle.SelectedItem.Text);
arr.Add(txtFName.Text);
arr.Add(txtLName.Text);
arr.Add(RadioButtonList1.SelectedItem.Text);
arr.Add(txtPin.Text);
arr.Add(txtEmail.Text);
arr.Add(txtMobileNo.Text);
arr.Add(txtPhone.Text);
arr.Add(txtFaxno.Text);
on page load
if(arr.count>0)
{
if (arr.Count > 0)
{
txtFName.Text = arr[1].ToString();
txtLName.Text = arr[2].ToString();
txtDesignation.Text = arr[3].ToString();
txtEmail.Text = arr[4].ToString();
txtFaxno.Text = arr[5].ToString();
txtMobileNo.Text = arr[6].ToString();
txtPin.Text = arr[7].ToString();
txtPhone.Text = arr[8].ToString();
}
}
thanx for your support..[:)]
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to move value from one form to another
May 28, 2009 10:07 AM|LINK
If that many items are there I'll suggest not to use arrays as it will make it more complex if you had more than 20 items to store I would have used arrays but using normal session makes code more readable
To apply consition just do this way in page load
ArrayList arr = (ArrayList)Session["arr"];
if (arr!=null && arr.Count > 0)
{
txtFName.Text = arr[1].ToString();
txtLName.Text = arr[2].ToString();
txtDesignation.Text = arr[3].ToString();
txtEmail.Text = arr[4].ToString();
txtFaxno.Text = arr[5].ToString();
txtMobileNo.Text = arr[6].ToString();
txtPin.Text = arr[7].ToString();
txtPhone.Text = arr[8].ToString();
}
Also this is correct
Contact me
demoninside9
Participant
1182 Points
1697 Posts
Re: How to move value from one form to another
May 28, 2009 10:34 AM|LINK
on page load
There is no error but the filled control become blank...like control txtLName.Text doent have value which i filled before.....?
thanx for ur continuous support ..:)
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to move value from one form to another
May 28, 2009 11:00 AM|LINK
I'll suggest follow the previous method that you used
Contact me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to move value from one form to another
May 28, 2009 11:03 AM|LINK
First code was working reason you saved in session and then getting it Now in case of arrays you are not saving it in session'
arr.Add(txtDesignation.Text);
arr.Add(ddlTitle.SelectedItem.Text);
arr.Add(txtFName.Text);
arr.Add(txtLName.Text);
arr.Add(RadioButtonList1.SelectedItem.Text);
arr.Add(txtPin.Text);
arr.Add(txtEmail.Text);
arr.Add(txtMobileNo.Text);
arr.Add(txtPhone.Text);
arr.Add(txtFaxno.Text);
Session["arr"] = arr;
Contact me
demoninside9
Participant
1182 Points
1697 Posts
Re: How to move value from one form to another
May 28, 2009 11:15 AM|LINK
Still it shows
Object reference not set to an instance of an object.
on first line of this code
arr.Add(txtDesignation.Text); // here it shows error
arr.Add(ddlTitle.SelectedItem.Text);
arr.Add(txtFName.Text);
arr.Add(txtLName.Text);
arr.Add(RadioButtonList1.SelectedItem.Text);
arr.Add(txtPin.Text);
arr.Add(txtEmail.Text);
arr.Add(txtMobileNo.Text);
arr.Add(txtPhone.Text);
arr.Add(txtFaxno.Text);
Session["arr"] = arr;
demoninside9
Participant
1182 Points
1697 Posts
Re: How to move value from one form to another
May 28, 2009 11:24 AM|LINK
i am not having much knowledge about arrays.
for this time i shld go for sessions method which i used previous.
thank u very much dear. [:)]
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to move value from one form to another
May 28, 2009 11:30 AM|LINK
If you are new make things simple once you got it working start refining you can always post your code on forums and ask people to suggest
But yes if you make that correction I think it will work
Contact me
demoninside9
Participant
1182 Points
1697 Posts
Re: How to move value from one form to another
May 29, 2009 04:44 AM|LINK
Hi...
Now i have written
on button click
ArrayList arr=new ArrayList();
protected void btnOrg_Click1(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtDesignation.Text))
{
arr.Add(txtDesignation.Text);
}
else if (!String.IsNullOrEmpty(ddlTitle.SelectedItem.Text))
{
arr.Add(ddlTitle.SelectedItem.Text);
}
else if (!String.IsNullOrEmpty(txtFName.Text))
{
arr.Add(txtFName.Text);
}
else if (!String.IsNullOrEmpty(txtLName.Text))
{
arr.Add(txtLName.Text);
}
else if (!String.IsNullOrEmpty(txtPin.Text))
{
arr.Add(txtPin.Text);
}
else if (!String.IsNullOrEmpty(txtEmail.Text))
{
arr.Add(txtEmail.Text);
}
else if (!String.IsNullOrEmpty(txtMobileNo.Text))
{
arr.Add(txtMobileNo.Text);
}
else if (!String.IsNullOrEmpty(txtPhone.Text))
{
arr.Add(txtFaxno.Text);
}
else
{
}
Session["arr"] = arr;
}
And on page load
On Page_Load()
ArrayList arr = (ArrayList)Session["arr"];
if (arr != null && arr.Count > 0)
{
txtFName.Text = arr[1].ToString();
txtLName.Text = arr[2].ToString();
txtDesignation.Text = arr[3].ToString();
txtEmail.Text = arr[4].ToString();
txtFaxno.Text = arr[5].ToString();
txtMobileNo.Text = arr[6].ToString();
txtPin.Text = arr[7].ToString();
txtPhone.Text = arr[8].ToString();
}
it still shows error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
thanx