• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 972
  • Last Modified:

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

0
rondre
Asked:
rondre
  • 13
  • 9
  • 2
  • +1
3 Solutions
 
Tom BeckCommented:
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;
0
 
PlatoConsultantCommented:
place a breakpoint and check the generated sql query, and try to runit in query builder
0
 
rondreAuthor Commented:
@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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Tom BeckCommented:
My mistake, the New should be lower case for C#.
0
 
rondreAuthor Commented:
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
0
 
Tom BeckCommented:
Try it this way:

cmdUpdate.Parameters["@MEMID"].Value = memuserid;
0
 
rondreAuthor Commented:
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.
0
 
rondreAuthor Commented:
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
0
 
Tom BeckCommented:
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.
0
 
Tom BeckCommented:
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.
0
 
rondreAuthor Commented:
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!
0
 
Tom BeckCommented:
Breakpoints, very simple. In Visual Studio, click in the left margin of the cs code view to set a breakpoint then press F5 to start debugging. Do whatever you do to initiate an update of the database and when the execution reaches the breakpoint, it will stop and you will be able to step through, one line at a time, and watch variable values as they are assigned.
breakpoints.jpg
0
 
rondreAuthor Commented:
thanks tommyboy - i will try this tonight when i get home (no vis stud here).

I appreciate all the help so far!
0
 
rondreAuthor Commented:
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!
0
 
Tom BeckCommented:
Have you tried MembershipUser m = Membership.GetUser(User.Identity.Name);
If the username parameter does not match an existing user, the method returns null. If left blank, it tries to get the name of the currently logged in membership user.

0
 
rondreAuthor Commented:
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?
0
 
Tom BeckCommented:
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.
0
 
rondreAuthor Commented:
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

0
 
rondreAuthor Commented:
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!
0
 
rondreAuthor Commented:
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!
0
 
ultrawebsitesCommented:
Remove/comment out all try - catch statements from the code and then run it again.

Also, have you enabled your Membership Provider in web.config?

It strikes me that you are trying to do too many things at once / going for gold before you've made sure some of the fundamentals are working. In particular, your membership provider does not seem to be working / correctly getting the membership profile (hence the NullReferenceException because it is 'null').

Can you simplify it down at go through one working piece at a time to find out what the problem is, and/or response.write a value from the profile?

HTH
Matt

0
 
Tom BeckCommented:
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.
0
 
rondreAuthor Commented:
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.
0
 
rondreAuthor Commented:
thanks for all the help.
0
 
ultrawebsitesCommented:
Try catch's are a killer when developing!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 13
  • 9
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now