Why does my page refresh when my button is clicked in ASP.NET?

Hi, I created a button in asp.net but when its clicked it automatically refreshes the page.  This is a problem bc any c# code that I write to happen on the click it gets lost bc the page refreshes.  When I click a regular html button it never refreshes if there is no code to tell the page to do so onclick.  Can someone please tell me why this is happening?  Is this normal for asp.net?

click on the Sign Up tab then click the Sign Up button:
http://auroriella.com/login.aspx
FairyBusinessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RainverseCommented:
Set the AutoPostback property to false
0
FairyBusinessAuthor Commented:
I tried this:

<form method="post" action="" runat="server" AutoPostBack="False">

Open in new window


and this:

           
<asp:Button id="submit" text="Sign Up" class="form-submit" runat="server" AutoPostBack="False" />

Open in new window


but the page still refreshes.
0
FairyBusinessAuthor Commented:
this is my entire form code:

<form method="post" action="" runat="server" AutoPostBack="False">
            <article class="align-left">
            <label>First Name<span class="red">*</span></label>
            <asp:TextBox id="firstname" value="" class="form-text" ValidationGroup="Group1" runat="server" /><br />
            <!--<asp:RequiredFieldValidator ErrorMessage="You cannot leave this field blank." runat="server" ControlToValidate="firstname" Display="dynamic" />-->
            <label>Last Name<span class="red">*</span></label>
            <asp:TextBox id="lastname" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Email Address<span class="red">*</span></label>
            <asp:TextBox id="email" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Password<span class="red">*</span></label>
            <asp:TextBox id="password" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Re-enter Password<span class="red">*</span></label>
            <asp:TextBox id="repassword" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </article>
            <article class="align-left">
            <label>Business Name<span class="red">*</span></label>
            <asp:TextBox id="business" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Employer ID Number<span class="red">*</span></label>
            <asp:TextBox id="eid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Tax ID Number<span class="red">*</span></label>
            <asp:TextBox id="tid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Business Address<span class="red">*</span></label>
            <asp:TextBox id="address" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <details class="align-left city">
                <label>City<span class="red">*</span></label>
                <asp:TextBox id="city" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left state">
                <label>State<span class="red">*</span></label>
                <asp:TextBox id="state" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left zip">
                <label>Zip<span class="red">*</span></label>
                <asp:TextBox id="zip" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            </article>
            <br />
            <asp:Button id="submit" text="Sign Up" class="form-submit" runat="server" AutoPostBack="False" />
        </form>

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ddayx10Commented:
1. If you made buttons before asp.net you may have made them like this:

<button id="btn" type="button" value="MyButton" />
<input id="btn2" type="button" value="MyOtherButton" />

These would not cause the page to "postback" or "refresh" as you say.

When you make an <asp:Button> then this creates an input of type "submit" which will submit a form or cause a "postback".

Your source for the button is this:

<input name="submit" class="form-submit" id="submit" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("submit", "", true, "", "", false, false))" type="submit" value="Sign Up"/>


2. >>When I click a regular html button it never refreshes if there is no code to tell the page to do so onclick<<

It would if you told it to(plain old HTML):
<button id="btn" type="submit" value="MyButton" />
<input id="btn2" type="submit" value="MyOtherButton" />


3. >>This is a problem bc any c# code that I write to happen on the click it gets lost bc the page refreshes.<<

There would be no point in writing c# code for the button.click if the page didnt postback to run the server-side c# click event. Unless you are using AJAX (which from your javascript you may be attempting... I dunno) on the button click to call c# somewhere on the server.

4. Just for the record the <asp:button> or any other button does not have or support an AutoPostback  property.

5. If you are trying to use AJAX from the button then you can either make sure your JavaScript for the button click function returns false:

<asp:button id="MyButton" runat="Server" Text="LogIn" OnClientClick="SomeAjaxCall();return false;" />

Or if your using AJAX maybe you don't want to use an asp:button here but instead use a good old fashioned html button.

OR....

If you are trying to call a server-side button click event to run some c# code then it needs to post back. If you are losing information or your page is not displaying as you want after this postback occurs then its because you have built your page with some conceptual flaws.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FairyBusinessAuthor Commented:
@ddayx10 thanks for all the info!

ok, I want to test my c# code to make sure it doesn't have any conceptual flaws.  In javascript I would use an alert and in php I would use echo.  What can I use in C# to see how far its making it into my c# code??

I have a function submit_Click() but its not doing anything in that function that I can see so far. . .
0
ddayx10Commented:
Well ideally you would use a breakpoint and debug.

1. In code behind click on the grey area next to a line of code to set a breakpoint <see screenshot>

2. Press F5 To start debugging. Check out the Debug menu at top for all commands including this.

3. Your project should start (website/app should open).

4. Click the button you want to see function (Login button I believe).

Debugger should take you to your breakpoint. You can then use F11 to "step into" the code, or F10 to "step over" a line of code. Remember to look at the debug menu.

If you don't debug then life is harder....

You could put this at any point

Response.Write("I made it to line whatever");

That will become really tedious.

What I meant about conceptually flawed would be something like:
(dont take the syntax too seriously here)

1. You write some code to make a label show the date in Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
       Label1.Text = datetime.now;
    }

2. In JavaScript you updated the Label to be the current time when a user did something like click a button.

3. You have an <asp:button> that has a click event where you did stuff. When you click this button the click event runs and it does its c# happiness, but dogonit the Label1.Text got changed back to the original time and you didnt want that!

Could have been avoided by putting a postback check on the original code:
    protected void Page_Load(object sender, EventArgs e)
    {
       if(!isPostBack) Label1.Text = datetime.now;
    }

Now this is very contrived, but my point is that lots of times people don't understand how when setting something up to work it may interplay with other things later in a way that was unexpected.
breakpointsample.jpg
0
ddayx10Commented:
Just for the heck of it I guess you could also do this to pop a JavaScript alert without potentially messing up your page layout:

Response.Write(@"<script type='text/javascript'>alert('Line X');</script>");
0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, First you have to use the update panel, put this form into update panel then use this,
If you require to not blank the textboxes after clicking on login button.

Me.txtEmail.Attributes.Add("value", txtEmail.Text)
Me.txtPassword.Attributes.Add("value",txtPassword.Text)

This code is require to put outside of the IsPostBack.

With the use of that, at the time of clicking on login button page don't get refresh and Email and Password don't get blank.
0
FairyBusinessAuthor Commented:
@ddayx10 ok I made a break point right after my submit_Click() function:

       
protected void submit_Click(object send, EventArgs e)
        {

Open in new window


the I hit F5. The page doesn't look the same as it does on my website but I clicked the Sign Up button and it went back to visual studio. It gave me 96 warnings and 1 error message:

Error      94      The CodeDom provider type "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.            

I still don't if its actually getting into my function though.


@samirbhogayta  What is the update panel? Where do I find this at and how do I put my form in it? Which code is required to be outside of the IsPostBack exactly??

If it helps, here is my login.aspx.cs file:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace loginUsers
{
    public partial class signup : System.Web.UI.Page
    {
        // enumeration
        private string firstName;
        private string lastName;
        private string userEmail;
        private string userPassword;
        private string userRePassword;
        private string businessName;
        private string EID;
        private string TID;
        private string userAddress;
        private string userCity;
        private string userState;
        private string userZip;
        private string hashPassword;
        private string query;

        // create the command and connection objects
        string connectionString = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                // Validate intially to force *s to appear before the first round-trip
                Validate("Group1");
                Response.Write(IsValid.ToString());
            }
        } // end method Page_Load method
        protected void submit_Click(object send, EventArgs e)
        {
            // retrieve sign up form informtion
            firstName = firstname.Text.Trim();
            lastName = lastname.Text.Trim();
            userEmail = email.Text.Trim();
            userPassword = password.Text.Trim();
            userRePassword = repassword.Text.Trim();
            businessName = business.Text.Trim();
            EID = eid.Text.Trim();
            TID = tid.Text.Trim();
            userAddress = address.Text.TrimEnd();
            userCity = city.Text.Trim();
            userState = state.Text.TrimEnd().TrimStart();
            userZip = zip.Text.Trim();

            if (!IsPostBack)
            {
                if (userPassword == userRePassword)
                {
                    // encrypt user's password for protection
                    hashPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "sha1");

                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        con.Open();

                        // get the DataReader
                        query = "ALTER TABLE Users AUTO_INCREMENT = 1 ";
                        query += "INSERT INTO Users (FirstName, LastName, Company, Email, TID, EID, Address, City, State, Zip, Password) ";
                        query += "VALUES ('firstName','lastName','userEmail',userPassword',userRePassword','businessName','EID','TID','userAddress',";
                        query += "'userCity','userState','userZip','userPassword')";
                        SqlCommand cmd = new SqlCommand(query, con);

                       /* if (cmd)
                        {
                            string message = "The user was successfuly created.";
                        }
                        else
                        {
                            string message = "The user could not be created.";
                        }*/
                    } // end using SqlConnection
                }
                else
                {
                    // create an instance of the errors class and send an error message to its constructor
                    errors error = new errors("The passwords you entered do not match. Please try again");
                    // tell the message method within the errors class where to display the label
                    error.message(this.PlaceHolder1);
                }
            } // if !IsPostBack
        } // end submit_Click method
    } // end class login
} // end displayCase namespace

Open in new window

0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, you have to put updatepanel from Ajax Extensions.

<asp:UpdatePanel id="Up1" runat="server">
your login form.
</asp:UpdatePanel>

protected void Page_Load(object sender, EventArgs e)
        {
Me.txtEmail.Attributes.Add("value", txtEmail.Text)
Me.txtPassword.Attributes.Add("value",txtPassword.Text)

            if (IsPostBack)
            {
                // Validate intially to force *s to appear before the first round-trip
                Validate("Group1");
                Response.Write(IsValid.ToString());
            }
        } // end method Page_Load method


0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello,

Error      94      The CodeDom provider type "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.

Solution for that error is this.

 It was something missing (which is always harder to find). In the web.config you need:

<compilers>
      <compiler language="vj#;vjs;vjsharp" extension=".jsl;.java" type="Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      </compiler>
</compilers>
0
FairyBusinessAuthor Commented:
@samirbhoqayta  Hi, for some reason when I put this into my web.config file:

  <compilers>
      <compiler language="vj#;vjs;vjsharp" extension=".jsl;.java" type="Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      </compiler>
</compilers>


I get this message in the browser:

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

It doesn't want to load my page.


When I take that out of my web.config file and just run the page I get this error:

Type 'System.Web.UI.UpdatePanel' does not have a public property named 'form'.

http://auroriella.com/login.aspx

Maybe I don't need the updatePanel?  I'm not sure what it does exactly.  I just want to see why my function isn't working submit_Click.
0
FairyBusinessAuthor Commented:
    <asp:UpdatePanel id="Up1" runat="server">
        <form method="post" action="" runat="server">
            <article class="align-left">
            <label>First Name<span class="red">*</span></label>
            <asp:TextBox id="firstname" value="" class="form-text" ValidationGroup="Group1" runat="server" /><br />
            <!--<asp:RequiredFieldValidator ErrorMessage="You cannot leave this field blank." runat="server" ControlToValidate="firstname" Display="dynamic" />-->
            <label>Last Name<span class="red">*</span></label>
            <asp:TextBox id="lastname" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Email Address<span class="red">*</span></label>
            <asp:TextBox id="email" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Password<span class="red">*</span></label>
            <asp:TextBox id="password" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Re-enter Password<span class="red">*</span></label>
            <asp:TextBox id="repassword" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </article>
            <article class="align-left">
            <label>Business Name<span class="red">*</span></label>
            <asp:TextBox id="business" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Employer ID Number<span class="red">*</span></label>
            <asp:TextBox id="eid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Tax ID Number<span class="red">*</span></label>
            <asp:TextBox id="tid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Business Address<span class="red">*</span></label>
            <asp:TextBox id="address" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <details class="align-left city">
                <label>City<span class="red">*</span></label>
                <asp:TextBox id="city" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left state">
                <label>State<span class="red">*</span></label>
                <asp:TextBox id="state" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left zip">
                <label>Zip<span class="red">*</span></label>
                <asp:TextBox id="zip" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            </article>
            <br />
            <asp:Button id="submit" text="Sign Up" class="form-submit" runat="server" OnClick="submit_Click" />
        </form>
        </asp:UpdatePanel>

Open in new window

0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, this updatepanel is use for refreshing the specific portion of the whole page. Put like this

<form>
<asp:UpdatePanel id="Up1" runat="server">
<table><tr><td></td></tr></table>
</asp:UpdatePanel>
</form>

sorry for previous code, it is my mistake.
0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:

        <form method="post" action="" runat="server">

<asp:UpdatePanel id="Up1" runat="server">
            <article class="align-left">
            <label>First Name<span class="red">*</span></label>
            <asp:TextBox id="firstname" value="" class="form-text" ValidationGroup="Group1" runat="server" /><br />
            <!--<asp:RequiredFieldValidator ErrorMessage="You cannot leave this field blank." runat="server" ControlToValidate="firstname" Display="dynamic" />-->
            <label>Last Name<span class="red">*</span></label>
            <asp:TextBox id="lastname" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Email Address<span class="red">*</span></label>
            <asp:TextBox id="email" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Password<span class="red">*</span></label>
            <asp:TextBox id="password" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Re-enter Password<span class="red">*</span></label>
            <asp:TextBox id="repassword" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </article>
            <article class="align-left">
            <label>Business Name<span class="red">*</span></label>
            <asp:TextBox id="business" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Employer ID Number<span class="red">*</span></label>
            <asp:TextBox id="eid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Tax ID Number<span class="red">*</span></label>
            <asp:TextBox id="tid" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <label>Business Address<span class="red">*</span></label>
            <asp:TextBox id="address" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            <details class="align-left city">
                <label>City<span class="red">*</span></label>
                <asp:TextBox id="city" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left state">
                <label>State<span class="red">*</span></label>
                <asp:TextBox id="state" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            <details class="align-left zip">
                <label>Zip<span class="red">*</span></label>
                <asp:TextBox id="zip" value="" class="form-text" ValidationGroup="Group1" runat="server" />
            </details>
            </article>
            <br />
            <asp:Button id="submit" text="Sign Up" class="form-submit" runat="server" OnClick="submit_Click" />
</asp:UpdatePanel>
        </form>

try this,
       
0
FairyBusinessAuthor Commented:
nope, even when I put the updatepanels inside of the form it still doesn't load my page.

forget that for a moment, and can you help me with getting my function to work? or at least testing it?

this is my function that I am trying to get to work:

        protected void submit_Click(object send, EventArgs e)
        {
            // retrieve sign up form informtion
            firstName = firstname.Text.Trim();
            lastName = lastname.Text.Trim();
            userEmail = email.Text.Trim();
            userPassword = password.Text.Trim();
            userRePassword = repassword.Text.Trim();
            businessName = business.Text.Trim();
            EID = eid.Text.Trim();
            TID = tid.Text.Trim();
            userAddress = address.Text.TrimEnd();
            userCity = city.Text.Trim();
            userState = state.Text.TrimEnd().TrimStart();
            userZip = zip.Text.Trim();

            if (!IsPostBack)
            {
                if (userPassword == userRePassword)
                {
                    // encrypt user's password for protection
                    hashPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "sha1");

                    using (SqlConnection con = new SqlConnection(connectionString))
                    {
                        con.Open();

                        // get the DataReader
                        query = "ALTER TABLE Users AUTO_INCREMENT = 1 ";
                        query += "INSERT INTO Users (FirstName, LastName, Company, Email, TID, EID, Address, City, State, Zip, Password) ";
                        query += "VALUES ('firstName','lastName','userEmail',userPassword',userRePassword','businessName','EID','TID','userAddress',";
                        query += "'userCity','userState','userZip','userPassword')";
                        SqlCommand cmd = new SqlCommand(query, con);

                       /* if (cmd)
                        {
                            string message = "The user was successfuly created.";
                        }
                        else
                        {
                            string message = "The user could not be created.";
                        }*/
                    } // end using SqlConnection
                }
                else
                {
                    // create an instance of the errors class and send an error message to its constructor
                    errors error = new errors("The passwords you entered do not match. Please try again");
                    // tell the message method within the errors class where to display the label
                    error.message(this.PlaceHolder1);
                }
            } // if !IsPostBack
        } // end submit_Click method

Open in new window


Its not working though.  And I can't how far its getting into the function, if it is at all. Help??
0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, one question is that, why are you put

if (!IsPostBack)

into the button click event.
0
ddayx10Commented:
I can't go 3 directions at once it hurts my head. The update panel may be a solution but I fail to see any evidence from what you've told me that it will help. You can't just plop one on the page like that anyway. It needed more specific instructions for you to try to utilize what was given. If samirbhogayta wants to ride that horse I'm gonna leave off and let 'im.

The compiler error you are getting (at least the most serious one you've shown) could be a faulty setting in the web.config. It could also be that you didn't install J# with your Visual Studio, but its most likely that you have a java file somewhere in your solution and it is causing that error.

Look when you build or run your application the normal "text" files are "compiled" into libraries or executables that can then be run by the server. During this compilation any errors in your code may cause the compiler to stop and it will give you a list of these errors. It may also give you some warnings about things you are doing that may not be a good idea.

Once this compilation process is finished the page will then run and can be utilized with the debugger. You can often choose to "run the code anyway" if the errors are not too significant it may give you an option to try to run anyway. So often a page will run even if it has problems.

Now setting up a simple site as you are learning and running the debugger is one thing. Loading up a huge site in Visual Studio with all sorts of bells and whistles and then trying to learn to debug it for the first time is wholely another matter.

I do not much suggest you try to learn how to debug in this scenario. If you really want to then you likely want to make a backup of your project and load that into Visual Studio. As I said before the likely cause of your noted error is having java files in your solution. These often have .java extensions. I can't say much more about that because I'm not a Java developer. If you "exclude" these files out of your project it will likely compile without those errors.

You can exclude files by right clicking on them in solution explorer and choosing "exclude". This will mark the files with an ".exclude" extension and they will not be included in the compile operation. You may also exclude entire folders if you like. If you are using a web application (and I believe you are) then I believe these files become hidden to you by default when they are excluded. Before you exclude anything look at the top of the Solution Explore for a "Show All Files" button. This is how you make any hidden files visible. Once you have chosen to exclude a file you may re-include it (make it like it was before) by simply right clicking and choosing "include in project".

Now again. I'm telling you not to mess up your application. Make a backup and work from that until you get an application free of errors. I think you will find this incredibly tedious and it may not be a good idea. You may be much better suited to open a simple small project and test out your debugging skills on that. Getting rid of a pile of compile errors on a huge project you have loaded up but never monitored like this before can be extremely difficult and requires a certain level of expertise or a whole lot of perseverence(sp).

Good luck.
0
ddayx10Commented:
I shouldn't say this:

Update Panel Requires a content template you guys :(

It also requires a scriptmanager .... sigh.

http://ajax.net-tutorials.com/controls/updatepanel-control

I'm not saying its not going to help, but whatever you can try it.

Debugging would have been a better option, but that alas is looking grim.

Did you try putting the alerting response.write I gave you into the btn.click event to see if its even firing?

0
FairyBusinessAuthor Commented:
@samirbhogayta  I put the if (!IsPostBack) into the click event because I am working with my database and I don't want to make calls to it that are unnecessary.  Perhaps I don't need it, but I'm still learning.

@ddayx10 No, I don't want you to go.  I don't see a 'Show All Files' button at the top of my explorer window. I don't see any java files in my website (not sure how they would have gotten there!).  

I have OnClick="submit_Click" for my asp.net form button. Would it make a difference if it was OnServerClick?  I'm just really struggling here for my function to do anything, or to see how can I get it to work. .
0
ddayx10Commented:
Another note on .java files.

If you have .java files you should also be able to right click on them and choose properties. There is a "build action" choice. You could set this to "content" if its set to "compile".

I want to keep disclaiming this though. I dont want you to muck around changing all sorts of things on your original code if its really important. Make a backup and get that running instead.
0
ddayx10Commented:
Ok no .java files fine. I'll go back to looking at this without the whole debugging fiasco :)

Put this in your BtnClick event and see if it pops when you click the button:

<see snippet>

I need to go back over the post and look at some stuff. In the meantime:

Talk to me a little more about what was distressing you at the beginning of this post. You were confused about the button you had causing a postback. It seemed to you that when this occured things were changing in a way you didnt expect. Like what?

Now we've gone on to the btnclick is not running its c# code and I wanna look into that but right now we dont have a really well defined problem/scenario.


protected void submit_Click(object send, EventArgs e)
{
   Response.Write(@"<script type='text/javascript'>alert('Line X');</script>");
   
   //rest of your code if you like
}

Open in new window

0
FairyBusinessAuthor Commented:
@ddayx10 the javascript worked!!

What's distressing me is that function doesn't seem to be doing anything.  Within the function it checks to make sure both passwords are the identical that the user gave:

               
if (userPassword == userRePassword)

Open in new window


if not then the else should fire:

                else
                {
                    // create an instance of the errors class and send an error message to its constructor
                    errors error = new errors("The passwords you entered do not match. Please try again");
                    // tell the message method within the errors class where to display the label
                    error.message(this.PlaceHolder1);
                }

Open in new window


So to test it I put int two different passwords and hit submit thinking the label will appear with the error message.  But of course nothing happens. This is the errors class by the way:

public class errors
{
    public string errorMessage;

    // constructor
	public errors(string warning)
	{
        errorMessage = warning;
	}

    // method for displaying the error message
    public void message(System.Web.UI.WebControls.PlaceHolder sectionToAddTo)
    {
        // create a new label
        Label newLabel = new Label();

        // assign error message to it
        newLabel.Text = errorMessage;
        newLabel.ID = "error";

        // add the label to sign up section
        sectionToAddTo.Controls.Add(newLabel);
    }
}

Open in new window

0
ddayx10Commented:
Alright. You're doing good. I actually saw it working on your site as well.

Anyway slow down. Go back up. Remember what samirbhogayta was asking about why you have the if(!ispostback) in there? Well that code block stops anything inside of it from running when you click this button. By definition a button click is always a postback.

Comment that out. I know you were worried about your database being used too much but even though you have the code mostly there you aren't actually executing anything on the database (you left that part out).

Remove that and take a look. Dont forget you can move that Response.Write around to get a better idea of what is happening.

0
ddayx10Commented:
You can also do stuff like this with your response.write <see snippet>

Here string.format allows us to use a placeholder {0} to stand in for a variable (or in this case expression) that we want to be placed in there.

string.format("some string in this case with a placeholder here {0}", somevariablehere);


Response.Write(string.Format("<script type='text/javascript'>alert('{0}');</script>",userPassword == userRePassword));

Open in new window

0
ddayx10Commented:
Alright well you either got to some stopping point, had an embolism from stress or simply passed out...not sure but I'm out till Monday. Hope you're doing good. l8r :)
0
FairyBusinessAuthor Commented:
It works!

Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.