Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 25, 2012 11:44 AM by hoopslife
May 24, 2012 11:39 AM|LINK
I have a default ASP.NET 4.0 Login Form which is auto-generated with an empty ASP.NET 4 application.
On the Login Form I have added two DropDown Controls and I pass the selected item text and values in session variables.
When the Login button is clicked, these session variables are created and page is supposed to redirected to another page.
Below is the code of the Login Button Click event:
protected void LoginButton_Click(object sender, EventArgs e)
reuse reuseableMethodsClass = new reuse();
VerifyUser verifyUser = new VerifyUser();
DropDownList ddlFy = LoginUser.FindControl("ddlFyYear") as DropDownList;
DropDownList ddlOffice = LoginUser.FindControl("ddlOffice") as DropDownList;
verifyUser.EnteredUserName = LoginUser.UserName;
verifyUser.EnteredPassword = LoginUser.Password;
bool verified = verifyUser.GetLoginStatus();
The problem is when I click the Login button, an error is displayed in the lines where I add DropDown values to the Session.
Error is: Object reference not set to an instance of an object.
Error is displayed in the three lines:
Session.Add("FinancialYear", ddlFy.SelectedItem.Text); Session.Add("LoggedOfficeName", ddlOffice.SelectedItem.Text); Session.Add("LoggedOfficeID", ddlOffice.SelectedItem.Value.ToString());
I think when I select option from the DropDown, the new value is not retained after postback.
May 24, 2012 11:53 AM|LINK
Do you have viewstate turned on for the controls?
May 24, 2012 11:55 AM|LINK
They were ON by default. I turned them OFF but the problem is still there.
I never cared about turning them OFF before.
May 24, 2012 01:03 PM|LINK
Well, you deffinetly need them on to have the values postback. Have you tried stepping through your code to see which specific control isn't sending the value over? Or is it all 3?
May 25, 2012 10:57 AM|LINK
All three. I set the breakpoint.
May 25, 2012 11:04 AM|LINK
Before adding the DropDownList value to Session, you need to check whether the DropDownList is null or not!
if(ddlFy != null)
Hope it helps u...
May 25, 2012 11:44 AM|LINK
Can you post the html? Make sure you have runat="server" for each controller.