Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help fixing the Avatar Image I am trying to add to my code.

I am using an xml file to store the data. My problem is the Avatar image I want displayed after the person registering selects it from the drop down list. The problem is it will work when I remove the "runat=server" and the "Type=image". Problem: It stops the form from working because the scripting to submit to the xml file. Since it requires the value and the select requires to runat on the server-side.

Avatar
Image
Display

Drop Down List
I.E Weed Farmer is chosen
The Weed Farmer image should populate the <img>

What I have tried:

XML
<UserLoginDetials>
  <users>
    <Avatar />
    <FullName />
    <Street />
    <City />
    <State />
    <Postal />
    <Contact />
    <Alternate />
    <EmailAddress />
    <UserName />
    <Password />
    <PinCode />
    <SecurityQuestion />
    <SecurityAnswer />
    <Roles />
</UserLoginDetials>

ASP.NET
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Security " %>
<%@ Import Namespace="System.IO" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"
  <script runat="server">
    private void Page_Load ( Object sender, EventArgs e )
      {
          String loginname = Request.QueryString["UserName"];
          String email = Request.QueryString["EmailAddress"];
        String password = Request.QueryString["Password"];

      if (null != loginname)
          UserName.Value = loginname;
      if (null != email)
          SecurityQuestion.Value = email;
      if (null != password)
          Password.Value = password;
      }
      
    private void AddUser_Click ( Object sender, EventArgs E )
        {
        if ( !Page.IsValid ) {
            Msg.Text = "Some required fields are missing";
            return;
            }
        DataSet ds = new DataSet ( );
        String userFile = "K10e20R20r07Y/UserInformation.xml";
        
        FileStream fs = new FileStream ( Server.MapPath ( userFile ),
            FileMode.Open,FileAccess.Read );
        StreamReader reader = new StreamReader ( fs );
        ds.ReadXml ( reader );
        fs.Close ( );
        
        DataRow newUser = ds.Tables [ 0 ] .NewRow ( );
        newUser["Avatar"] = Avatar.Value;
        newUser["FullName"] = FullName.Value;
        newUser["Street"] = Street.Value;
        newUser["City"] = City.Value;
        newUser["State"] = State.Value;
        newUser["Postal"] = Postal.Value;
        newUser["Contact"] = Contact.Value;
        newUser["Alternate"] = Alternate.Value;
        newUser["EmailAddress"] = EmailAddress.Value;
        newUser["UserName"] = UserName.Value;
        newUser["Password"] = Password.Value;
        newUser["PinCode"] = PinCode.Value;
        newUser["SecurityQuestion"] = SecurityQuestion.Value;
        newUser["SecurityAnswer"] = SecurityAnswer.Value;
        newUser["Roles"] = Roles.Value;
        ds.Tables[0].Rows.Add(newUser);
        ds.AcceptChanges ( );
        
        fs = new FileStream ( Server.MapPath ( userFile ), FileMode.Create,
            FileAccess.Write|FileAccess.Read );
        StreamWriter writer = new StreamWriter ( fs );
        ds.WriteXml ( writer );
        writer.Close ( );
        fs.Close ( );

        Response.Redirect("K10e20R20r07Y/UserAdded.aspx", false);
    }
  </script>

   <script type="text/javascript">
     <!--
       function checkPhone(obj) {
           str = obj.value.replace(/[^0-9]+?/g, '');
           switch (str.length) {
               case 0:
                   alert('Please enter numbers only.');
                   obj.select();
                   return;
               case 7:
                   str = str.substr(0, 3) + "-" + str.substr(3, 4);
                   break;
               case 10:
                   str = "(" + str.substr(0, 3) + ") " + str.substr(3, 3) + "-" + str.substr(6, 4);
                   break;
               default:
                   alert('Please enter a 7 digit phone number (with area code, if applicable).');
                   obj.select();
                   return;
           }
           obj.value = str;
       }
       //-->
  </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="BlueView" Runat="Server">
  <div class="demo">
<---------WON"T WORK -------------->

<img id="image" src="../app_images/faces/av00-anonymous.jpg" alt="" />

<select id="Avatar" runat="server" <big>onclick="setAvat()"</big> type="image">
    <option value="../app_images/faces/av00-anonymous.jpg" anonymous /option>
    <option value="../app_images/faces/av02-cannabisrevolution.png" cannabisrevolution /option>
    <option value="../app_images/faces/av05-weedfarmer.png" weedfarmer /option>
</select>

  <script language="javascript" type="text/javascript">
      function setAvat() {
          var img = document.getElementById("image");
          img.src = this.value;
          return false;
      }
      document.getElementById("Avatar").onchange = setAvat;
  </script>

<---------WON"T WORK -------------->
  
  Full Name: 
  <asp:RequiredFieldValidator ID="FullNameValidate" runat="server" ControlToValidate="FullName" Display="Static" ErrorMessage="* Required" /> 
  <asp:RegularExpressionValidator ID="regexpName" runat="server"     
                                    ErrorMessage="This expression does not validate." 
                                    ControlToValidate="FullName"     
                                    ValidationExpression="^[a-zA-Z'.\s]{1,40}$" /><br>
  
  Username:  
  <asp:RequiredFieldValidator ID="UsernameValidator" runat="server" ControlToValidate="UserName" Display="Static" ErrorMessage="* Required" /><br>
  

  Password:   
  unmask 
  <asp:RequiredFieldValidator ID="PasswordValidator" runat="server" ControlToValidate="Password" Display="Static" ErrorMessage="* Required" /><br>
  
  Security Pin:  
  <asp:RequiredFieldValidator ID="PinCodeValidator" runat="server" ControlToValidate="PinCode" Display="Static" ErrorMessage="* Required" /><br>
  
  Security Question:  
  <asp:RequiredFieldValidator ID="QuestionValidator" runat="server" ControlToValidate="SecurityQuestion" Display="Static" ErrorMessage="* Required" /><br>
  
  Security Answer:  
  <asp:RequiredFieldValidator ID="AnswerValidator" runat="server" ControlToValidate="SecurityAnswer" Display="Static" ErrorMessage="* Required" /><br>
  
    <asp:Label ID="Msg" runat="server" style="visibility:hidden">
  <!-- Persistent Forms: --><asp:CheckBox Visible="false" id="PersistForms" runat="server" autopostback="true"  />
  </div>
Posted
Updated 31-Jul-17 3:08am
v5
Comments
[no name] 30-Jul-17 1:09am    
I am still trying to solve this issue, but I got it to change the image now. However once the image changes from the default image displayed. I only get the image for no image found. To get to this point I add onclick="setAvat()" to the select menu.

I know there is something I am missing or over look. Is there any help out there?
[no name] 31-Jul-17 9:10am    
This problem has been solved. I found the problem and now it is working great. I found that I was using jquery 1.11.1, I changed it to jquery 1.11.2 and everything started working.

1 solution

This problem has been solved. I found the problem and now it is working great. I found that I was using jquery 1.11.1, I changed it to jquery 1.11.2 and everything started working.
 
Share this answer
 
v2
Comments
PIEBALDconsult 1-Aug-17 0:24am    
Please don't answer your own question. Use "Improve Question" to add information there.
[no name] 1-Aug-17 0:34am    
No one else would sat for 2 days. Hmm.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900