Link to home
Start Free TrialLog in
Avatar of rondre
rondreFlag for United States of America

asked on

Update Statement not working

I have a profile page I've made and need to have the ability to update the database, but I can't for the life of me understand why the update is not working.  There are no errors that I can see but nothing happens.  Please analyze my code and let me know what the problem is if possible.
codebehind:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Web.Security;
using System.Drawing;
using System.Drawing.Drawing2D; 

public partial class profileupdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HyperLink hl;

        try
        {
            hl = Master.FindControl("_members") as HyperLink;
            hl.CssClass = "current_page_item";
        }
        catch (Exception)
        {
        }

        string getMemInfoSQL = "Select MEMBER_ID, MEMBER_SNAME, MEMBER_PIC, MEMBER_PHONE FROM MEMBER WHERE MEMBER_ID = @MEMID";

        SqlConnection myConnection = new SqlConnection();
        string connectionString = WebConfigurationManager.ConnectionStrings["DBSFL"].ConnectionString;
        SqlConnection dbconn = new SqlConnection(connectionString);

        SqlCommand cmdread = new SqlCommand(getMemInfoSQL, dbconn);
        SqlDataReader myReader1;

        MembershipUser m = Membership.GetUser();
        string memberuserid = m.ProviderUserKey.ToString();

        cmdread.Parameters.AddWithValue("@MEMID", memberuserid);

        try
        {
            dbconn.Open();

            myReader1 = cmdread.ExecuteReader();
            myReader1.Read();

            if (myReader1.HasRows)
            {
                String memimage = Convert.ToString(myReader1["MEMBER_PIC"]);
                String memsname = Convert.ToString(myReader1["MEMBER_SNAME"]);
                String memphone = Convert.ToString(myReader1["MEMBER_PHONE"]);

                txtSName.Text = memsname;
                txtPhone.Text = memphone;
                if (memimage == "")
                {
                    imgAvatar.Visible = false;
                }
                imgAvatar.ImageUrl = memimage;
            }
            myReader1.Close();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.ToString(), ex);
        }
        finally
        {
            dbconn.Close();
        }
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        MembershipUser m = Membership.GetUser();

        string memuserid = m.ProviderUserKey.ToString();
        string membersitename = txtSName.Text;
        string memberphone = txtPhone.Text;
        string mempicloc = sqltest.Text;
        string updateSQL = "";

        updateSQL = "Update MEMBER set MEMBER_SNAME = @MEMSNAME, MEMBER_PHONE = @MEMPHONE, MEMBER_PIC = @MEMPIC WHERE MEMBER_ID = @MEMID";

        string connectionString = WebConfigurationManager.ConnectionStrings["DBSFL"].ConnectionString;
        SqlConnection dbconn = new SqlConnection(connectionString);
        SqlCommand cmdUpdate = new SqlCommand(updateSQL, dbconn);

        cmdUpdate.Parameters.AddWithValue("@MEMID", memuserid);
        cmdUpdate.Parameters.AddWithValue("@MEMSNAME", membersitename);
        cmdUpdate.Parameters.AddWithValue("@MEMPHONE", memberphone);
        cmdUpdate.Parameters.AddWithValue("@MEMPIC", mempicloc);

        try
        {
            dbconn.Open();
            cmdUpdate.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.ToString(), ex);
        }
        finally
        {
            dbconn.Close();
        }

        Response.Redirect("members.aspx");

    }

    protected void profilePicUpload_UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        if (profilePicUpload.HasFile)
        {
            profilePicUpload.SaveAs(Server.MapPath("~/MemImages/" + System.IO.Path.GetFileName(e.filename)));
            sqltest.Text = "~/MemImageThumbs/" + System.IO.Path.GetFileName(e.filename);
            string destimg = "~/MemImages/" + System.IO.Path.GetFileName(e.filename);
            resizeimage(100, 100, "MemImageThumbs", destimg, System.IO.Path.GetFileName(e.filename));
            UpdatePanel1.Update();
        }
    }

    public void resizeimage(int tw, int th, string destfold, string srcimg, string fname)
    {
        int thumbWidth = tw;  //Max width allowed
        int thumbHeight = th; //Max height allowed
        decimal twidth = Convert.ToDecimal(thumbWidth);
        decimal theight = Convert.ToDecimal(thumbHeight);
        decimal heightdiff;
        decimal widthdiff;

        string src;
        string imgname = Convert.ToString(fname);
        src = srcimg;

        String dest = Server.MapPath("~/" + destfold + "/" + imgname); //absolute location of the new image created(thumbnail) 
        System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(src));

        //- Create a System.Drawing.Bitmap with the desired width and height of the thumbnail.
        int srcWidth = image.Width;
        int srcHeight = image.Height;

        if (srcWidth > thumbWidth)  //example sw = 800  tw = 640  
        {
            widthdiff = srcWidth / twidth;  // wd = 1.25
            if (srcHeight > thumbHeight)  //example sh = 500 th = 420
            {
                heightdiff = srcHeight / theight;  //hd = 1.19
                if (widthdiff > heightdiff)  // 1.25 > 1.19
                {
                    theight = srcHeight / widthdiff;  // 800 div 1.25  = 640
                    twidth = srcWidth / widthdiff;   //500 div 1.28
                    thumbHeight = Convert.ToInt32(theight);  // 800 div 1.25  = 640
                    thumbWidth = Convert.ToInt32(twidth);    // 500 div 1.25  = 400
                }
                else  // say hd was 1.28
                {
                    theight = srcHeight / heightdiff; //800 div 1.28
                    twidth = srcWidth / heightdiff;   //500 div 1.28
                    thumbHeight = Convert.ToInt32(theight);  // 800 div 1.25  = 640
                    thumbWidth = Convert.ToInt32(twidth);    // 500 div 1.25  = 400
                }
            }
            else  // ex sw = 800 sh = 400
            {
                theight = srcHeight / widthdiff;  // 800 div 1.25  = 640
                twidth = srcWidth / widthdiff;   //500 div 1.28
                thumbHeight = Convert.ToInt32(theight);  // 800 div 1.25  = 640
                thumbWidth = Convert.ToInt32(twidth);    // 500 div 1.25  = 400
            }
        }
        else  //example sw = 600
        {
            if (srcHeight > thumbHeight)  // sh = 450
            {
                heightdiff = srcHeight / theight;  // wd = 1.07
                theight = srcHeight / heightdiff; //800 div 1.28
                twidth = srcWidth / heightdiff;   //500 div 1.28
                thumbHeight = Convert.ToInt32(theight);  // 800 div 1.25  = 640
                thumbWidth = Convert.ToInt32(twidth);    // 500 div 1.25  = 400
            }
            else
            {
                thumbHeight = srcHeight;
                thumbWidth = srcWidth;
            }
        }

        Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);

        //- Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the high quality scaled image
        System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);

        //- Set the System.Drawing.Graphics object property SmoothingMode to HighQuality
        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        //- Set the System.Drawing.Graphics object property CompositingQuality to HighQuality
        gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

        //- Set the System.Drawing.Graphics object property InterpolationMode to High
        gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

        //- Draw the original image into the target Graphics object scaling to the desired width and height
        System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
        gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);

        //- Save to destination file
        bmp.Save(dest);

        //- dispose / release resources
        bmp.Dispose();
        image.Dispose();
    }
}


main page:

<%@ Page Title="" Language="C#" MasterPageFile="~/SFL.master" AutoEventWireup="true" CodeFile="profileupdate.aspx.cs" Inherits="profileupdate" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
SFL 2010 Profile Update
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="lblError" runat="server" />
    <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajaxToolkit:ToolkitScriptManager>
    <div id="page">
	<div id="page-bgtop">
		<div id="page-bgbtm">
			<div id="content">
				<div class="post">
					<div class="post-bgtop">
						<div class="post-bgbtm">
							<h2 class="title"><a href="#">Profile Update</a></h2>
							    <br /><asp:Label ID="sqltest" runat="server" Text=""></asp:Label><br /><br />
								
								<label for="curavatar" class="contactlabel">Current Avatar</label>
                                <asp:Image ID="imgAvatar" runat="server" /><br />
								<label for="txtSName" class="contactlabel">Site Name</label>
                                <asp:TextBox ID="txtSName" runat="server"></asp:TextBox><br />
                                <label for="txtPhone" class="contactlabel">Phone Number:</label>
                                <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="999\-999\-9999" MaskType="Number" Enabled="True" TargetControlID="txtPhone">
                                </ajaxToolkit:MaskedEditExtender>
                                <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox><br />
                                <label for="profilePicUpload" class="contactlabel">Avatar:</label>
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <ajaxToolkit:AsyncFileUpload ID="profilePicUpload" runat="server" OnUploadedComplete="profilePicUpload_UploadComplete" />
                                    </ContentTemplate></asp:UpdatePanel><br />	
                                    <label for="btnUpdate" class="contactlabel">&nbsp;</label>							
                                    <asp:Button ID="btnUpdate" runat="server" Text="Update Profile" OnClick="btnUpdate_Click" />
						</div>
					</div>
				</div>
		    </div>
			<!-- end #content -->
			<div id="sidebar">
				<ul>
					<li>
						<h2>My Tools</h2>
						<ul>
                            <li><a href="profileupdate.aspx"><img src="images/editprofile.jpg" />&nbsp;&nbsp;Edit Profile</a></li>
                            <li><a href="talkshit.aspx"><img src="images/talkshit.jpg" />&nbsp;&nbsp;Talk Shit</a></li>
                            <li><a href="traderequest.aspx"><img src="images/trade.jpg" />&nbsp;&nbsp;Request Trade</a></li>
                            <li><a href="placesidebet.aspx"><img src="images/sidebet.jpg" />&nbsp;&nbsp;Place Sidebet</a></li>
                            <li><a href="updatelineup.aspx"><img src="images/lineup.jpg" />&nbsp;&nbsp;Update My Lineup</a></li>
						</ul>
					</li>
					<li>
						<h2>Quick Tools</h2>
						<ul>
                            <li><a href="players.aspx"><img src="images/players.jpg" />&nbsp;&nbsp;View Players</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<!-- end #sidebar -->
			</div>
	</div>
</div>
</asp:Content>

Open in new window

Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Try this, it always works for me, but I could not tell you why.
Instead of AddWithValue, try it longhand and specify the data type and size like this:

cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@MEMID", System.Data.SqlDbType.VarChar, 50, "MEMID")) ;

Then say:

cmdUpdate.Parameters("@MEMID").Value = memuserid;
place a breakpoint and check the generated sql query, and try to runit in query builder
Avatar of rondre

ASKER

@tommy - I tried adding this but get errors such as:

the name new does not exist in the current context
also on the word sqlparameter and the to closing parens.

@plato - not really familiar with breakpoints - added one but don't know what i'm looking for - is there a site that talks about them more?
My mistake, the New should be lower case for C#.
Avatar of rondre

ASKER

thanks tommy - that fixed the line for the adding of the parameters (now not receiving errors), but i'm getting another error on the line:

        cmdUpdate.Parameters("@MEMID").Value = memuserid;

it is telling me:

Non-invocable member 'System.Data.SqlClient.SqlCommand.Paramters' cannot be used like a method.

Any ideas here - is there a diff. namespace that needs to be included?  Also - i did some other testing in the meantime and took the parameters out and wrote the query like so:

Update MEMBER set MEMBER_SNAME = '" + membersitename + "' ...
and wrote that value to a label - and it seems that the main page gets funky from the asyncfileupload tool - I'm not sure if that is throwing it off or not, but it doesn't read the values of the textboxes properly - I'm so confused because I don't see why this isn't working either way I do it.

thanks for the help
Try it this way:

cmdUpdate.Parameters["@MEMID"].Value = memuserid;
Avatar of rondre

ASKER

Thanks - no more errors, but the update is still not working.  It doesn't make sense to me at all - I've got a ton of experience with SQL and I don't know why this isn't updating.  What doesn't make sense is I can run the same query in SQL server tool on the hosted site and it works fine - I'm thinking there has to be something going on with the page feeding info to the query - I will look into this more but I suspect the problem lies with the ajax toolkit asyncfileupload part.
Avatar of rondre

ASKER

So I took out the asyncfileupload portion completely from the .aspx page and codebehind- the update is still not working.  I'm at a loss as to what is going on here
How about instead of
Update MEMBER set MEMBER_SNAME = '" + membersitename + "'
you set some hard values?

Are you using Visual Studio? Breakpoints are the next logical step.
Just thought of something else.
Could this be a permissions problem? Maybe the account you are using has read privileges (SELECT works) but not write privileges (UPDATE does not work). This may explain why it works when you use the SQL server tool on the hosted site because you have elevated privileges when logged in directly.
Avatar of rondre

ASKER

The site is hosted through godaddy - I've never had to setup anything before and I've been able to run insert statements galore on the site so i'm not sure why an update would be different.  I don't see any sql server settings in their db tool that talk about permissions.

can you explain breakpoints a little more - i've never used them and platoconsultant mentiond that as well - might be the next step but I'm not sure how they work.  Perhaps there is a link or tutorial you're familiar with for this?

thanks!
SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rondre

ASKER

thanks tommyboy - i will try this tonight when i get home (no vis stud here).

I appreciate all the help so far!
Avatar of rondre

ASKER

nm - i remoted into home system and ran this - it comes up with a popup highlighting this section:

string memberuserid = m.ProviderUserKey.ToString();

The box says:

NullReferenceException was unhandled by user code
Object reference not set to an instance of an object

The clipboard exception details is below:


System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_jxr-lazg"
  StackTrace:
       at profileupdate.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\ron.smith\My Documents\SFL\2010\profileupdate.aspx.cs:line 38
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

This always looks greek to me - If it helps, this is coming up on the first time I use the lines:

        MembershipUser m = Membership.GetUser();
        string memberuserid = m.ProviderUserKey.ToString();

If there is a better way to get the userid from asp.net membership, I'm all ears...err...eyes

thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rondre

ASKER

I just tried that - it's still not updating.  If there was no value for the userid - wouldn't I get an error from the sql statement rather than it just not working?
Still getting the popup error in VS?
You would get an error from the sql statement if there was no userid, but how is it handled? Are you sure you are able to see the exception being thrown? This looks foreign to me:
catch (Exception ex)
        {
            throw new Exception(ex.ToString(), ex);
        }
Why throw a new exception when the exception you want has already been caught? Why not:
catch (Exception ex)
{
   this.someLabel.text = ex.toString();
}
So you can print it to something visible.

How about hard coding a membership user name that you know exists in the database just for testing purposes.
Avatar of rondre

ASKER

I updated that as specified and assigned it to a label on the page - still no luck tho.  Attaching the code from the 2 files for review - I really think there is something screwy going on with the membership part now.
codebehind:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Web.Security;
using System.Drawing;
using System.Drawing.Drawing2D;

public partial class profileupdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HyperLink hl;

        try
        {
            hl = Master.FindControl("_members") as HyperLink;
            hl.CssClass = "current_page_item";
        }
        catch (Exception)
        {
        }

        string getMemInfoSQL = "Select MEMBER_ID, MEMBER_SNAME, MEMBER_PIC, MEMBER_PHONE FROM MEMBER WHERE MEMBER_ID = @MEMID";

        SqlConnection myConnection = new SqlConnection();
        string connectionString = WebConfigurationManager.ConnectionStrings["DBSFL"].ConnectionString;
        SqlConnection dbconn = new SqlConnection(connectionString);

        SqlCommand cmdread = new SqlCommand(getMemInfoSQL, dbconn);
        SqlDataReader myReader1;

        MembershipUser m = Membership.GetUser(User.Identity.Name);
        string memberuserid = m.ProviderUserKey.ToString();

        lblmemid.Text = memberuserid;

        cmdread.Parameters.AddWithValue("@MEMID", memberuserid);

        try
        {
            dbconn.Open();

            myReader1 = cmdread.ExecuteReader();
            myReader1.Read();

            if (myReader1.HasRows)
            {
                String memimage = Convert.ToString(myReader1["MEMBER_PIC"]);
                String memsname = Convert.ToString(myReader1["MEMBER_SNAME"]);
                String memphone = Convert.ToString(myReader1["MEMBER_PHONE"]);

                txtSName.Text = memsname;
                txtPhone.Text = memphone;
                if (memimage == "")
                {
                    imgAvatar.Visible = false;
                }
                imgAvatar.ImageUrl = memimage;
            }
            myReader1.Close();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.ToString(), ex);
        }
        finally
        {
            dbconn.Close();
        }
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        MembershipUser m1 = Membership.GetUser(User.Identity.Name);

        string memuserid = m1.ProviderUserKey.ToString();
        string sname = txtSName.Text;
        string memberphone = txtPhone.Text;
//        string updateSQL = "Update MEMBER set MEMBER_SNAME = @MEMSNAME, MEMBER_PHONE = @MEMPHONE WHERE MEMBER_ID = @MEMID";
        string updateSQL = "Update MEMBER set MEMBER_SNAME = '" + sname + "', MEMBER_PHONE = '" + memberphone + "' WHERE MEMBER_ID = @MEMID";

        string connectionString = WebConfigurationManager.ConnectionStrings["DBSFL"].ConnectionString;
        SqlConnection dbconn = new SqlConnection(connectionString);
        SqlCommand cmdUpdate = new SqlCommand(updateSQL, dbconn);
/*
        cmdUpdate.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MEMID", System.Data.SqlDbType.VarChar, 50, "MEMID"));
        cmdUpdate.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MEMSNAME", System.Data.SqlDbType.VarChar, 50, "MEMID"));
        cmdUpdate.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MEMPHONE", System.Data.SqlDbType.VarChar, 50, "MEMID"));
        cmdUpdate.Parameters["@MEMID"].Value = memuserid;
        cmdUpdate.Parameters["@MEMSNAME"].Value = sname;
        cmdUpdate.Parameters["@MEMPHONE"].Value = memberphone;
*/
        try
        {
            dbconn.Open();
            cmdUpdate.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            this.lblError.Text = ex.ToString();
        }
        finally
        {
            dbconn.Close();
        }

        Response.Redirect("members.aspx");

    }
}



.aspx


<%@ Page Title="" Language="C#" MasterPageFile="~/SFL.master" AutoEventWireup="true" CodeFile="profileupdate.aspx.cs" Inherits="profileupdate" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
SFL 2010 Profile Update
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <asp:Label ID="lblError" runat="server" />
    <div id="page">
	<div id="page-bgtop">
		<div id="page-bgbtm">
			<div id="content">
				<div class="post">
					<div class="post-bgtop">
						<div class="post-bgbtm">
							<h2 class="title"><a href="#">Profile Update</a></h2>
							    <br /><asp:Label ID="sqltest" runat="server" Text=""><br /><br /></asp:Label><asp:Label ID="lblmemid" runat="server" Text=""></asp:Label><br /><br />
								
								<label for="curavatar" class="contactlabel">Current Avatar</label>
                                <asp:Image ID="imgAvatar" runat="server" /><br />
								<label for="txtSName" class="contactlabel">Site Name</label>
                                <asp:TextBox ID="txtSName" runat="server"></asp:TextBox><br />
                                <label for="txtPhone" class="contactlabel">Phone Number:</label>
                                <asp:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="999\-999\-9999" MaskType="Number" Enabled="True" TargetControlID="txtPhone">
                                </asp:MaskedEditExtender>
                                <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox><br />
                                    <label for="btnUpdate" class="contactlabel">&nbsp;</label>							
                                    <asp:Button ID="btnUpdate" runat="server" Text="Update Profile" OnClick="btnUpdate_Click" />
						</div>
					</div>
				</div>
		    </div>
			<!-- end #content -->
			<div id="sidebar">
				<ul>
					<li>
						<h2>My Tools</h2>
						<ul>
                            <li><a href="profileupdate.aspx"><img src="images/editprofile.jpg" />&nbsp;&nbsp;Edit Profile</a></li>
                            <li><a href="talkshit.aspx"><img src="images/talkshit.jpg" />&nbsp;&nbsp;Talk Shit</a></li>
                            <li><a href="traderequest.aspx"><img src="images/trade.jpg" />&nbsp;&nbsp;Request Trade</a></li>
                            <li><a href="placesidebet.aspx"><img src="images/sidebet.jpg" />&nbsp;&nbsp;Place Sidebet</a></li>
                            <li><a href="updatelineup.aspx"><img src="images/lineup.jpg" />&nbsp;&nbsp;Update My Lineup</a></li>
						</ul>
					</li>
					<li>
						<h2>Quick Tools</h2>
						<ul>
                            <li><a href="players.aspx"><img src="images/players.jpg" />&nbsp;&nbsp;View Players</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<!-- end #sidebar -->
			</div>
	</div>
</div>
</asp:Content>

Open in new window

Avatar of rondre

ASKER

I just realized in the pageload i didn't change it there too.  I made the change and it still doesn't work.  However, here's something odd.  I clicked on my logout button after trying this a couple times and got this error:

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 36:
Line 37:         MembershipUser m = Membership.GetUser(User.Identity.Name);
Line 38:         string memberuserid = m.ProviderUserKey.ToString();
Line 39:
Line 40:         lblmemid.Text = memberuserid;
...


It def seems like something funny is going on w/ membership here - have you any thoughts on scrapping membership and writing custom login info?  This is my own personal fantasy football site that is just used by 12 people for fun - just thought I could save time w/ membership even tho  I haven't used it in the past.

Any info is appreciated good or bad - thanks!
Avatar of rondre

ASKER

If it helps at all to see what's happening, you can sign into the site:

http://www.smithfantasyleague.com

login info is test for both user and password - click on update profile link (from members page) or the edit profile in the main part of that page - it will take you to the profileupdate.aspx page which is what was coded - might help you follow along and you can see if you get any errors.

I have it setup right now to not redirect the page but to response.write it at the top - you'll have to highlight it to see it tho.

thanks for your help!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I followed the link and directions and got the error you mentioned when I tried to logout.

I don't think you should give up on the Membership Provider. Building from scratch is difficult and loaded with security concerns. My experience with Membership is limited; one website two years ago. i remember it being fairly easy to implement, I had no difficulties, and it is still in use today.
Avatar of rondre

ASKER

I finally figured out the problem - the page was getting posted back with the same values it started with from the database.  I wrapped most of the page load in between

if (!ispostback)
{
...
}

and now it works perfectly.  thanks for all your help - will divvy up the points.
Avatar of rondre

ASKER

thanks for all the help.
Avatar of ultrawebsites
ultrawebsites

Try catch's are a killer when developing!