For those who worked with bootstrap, knows it does not support input type = file, so I hide the asp:fileupload using jQuery (after document ready), and have and for the solution (as you can see from the code
<script type="text/javascript">
$(document).ready(function ()
{
$('#columnSelect').change(function ()
{
getImportColumnOrder();
});
// change file upload style similiar to bootstrap style
//$('#uploader').hide();
$('#uploader').change(function ()
{
var val = $(this).val();
var file = val.split(/[\\/]/);
$('#file').val(file[file.length - 1]);
});
});
function getImportColumnOrder()
{
var order = '';
$('#selectOrer').val('');
$('select', $('#MappingTable')).each(function ()
{
order += $(this).prop('selectedIndex') + ',';
});
$('#selectOrder').val(order.substr(0, order.length - 1));
}
</script>
<div class="span12">
<asp:DropDownList ID="ddl_DBTableList" runat="server" CssClass="combobox" Style="display: inline">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Import_Test">Import_Test</asp:ListItem>
</asp:DropDownList>
<asp:FileUpload ID="uploader" runat="server" CssClass="btn" />
<div class="input-append" style="display: inline;">
<input id="file" class="input-medium" type="text" />
<a class="btn" onclick="$('input[id=uploader]').click();">Select File</a>
</div>
<p />
<div>
<asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" />
</div>
<p />
<asp:Label ID="result" runat="server" ForeColor="Red"></asp:Label>
<p />
<asp:Label ID="data" runat="server" BackColor="#CCCCCC"></asp:Label>
<p />
<asp:Button ID="btn_import" runat="server" Text="Next" OnClick="doImport" OnClientClick="getImportColumnOrder();return true;" Visible="false" CssClass="btn btn-success" />
</div>
Steps are click on the "Select File", a file chooser popped up for file selection. After double clicked a file, the file location gets displayed in , and also the asp fileupload control.
In Chrome and FF, when I clicked btn_uplaod (button), it runs as supposed. In IE, it will clear the fileupload's content and does nothing (a client side action) and will not do any postback.
If this is a program problem, then maybe Chrome and FF will not run correctly. I'm suspecting is there anything that I need to add to make IE run as suppose to?
image after click upload (IE), (Browse link is cleared)
image after click upload (Chrome), (Run as supposed to)
thanks!
I've made a simple version for those of you who wants to try on Visual studio:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="postback_problem.aspx.cs" Inherits="postback_problem" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="uploader" runat="server" CssClass="btn" /> <div> <input id="file" class="input-medium" type="text" /> <a onclick="$('input[id=uploader]').click();">Select File</a> </div> <p /> <div> <asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" /> </div> <asp:Label ID="result" runat="server"></asp:Label> </div> </form> </body> </html>
and
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class postback_problem : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void doUpload(object sender, EventArgs e) { result.Text = "no problem!"; } }
Related
I'm sorry in advance if this seems to be a beginners question and wasted some of your time, but it does really bother me and I would really appreciate it if someone could help.
I'm simply creating a "zone" if you will, where the user inputs a word/sentence which are tasks, and then can check if the task was completed or not and/or if the word/sentence needs to be changed.
So in the end, what I need is a textbox lets say where the user inputs a specific number supposed x, and generates x times this div.
Here is the code (unfortunately I could not post pics since I do not have enough reputation..)
ASP.NET code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="GMode.tiz.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>whatevz</title>
<link href="StyleSheet1.css" rel="stylesheet" />
<script src="../jquery-1.11.3.min.js"></script>
<script src="../functions.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div class="singleContainer">
<div class="lblPlace">
<asp:Label ID="lbl" runat="server" Text="Input Task"></asp:Label>
<asp:TextBox ID="hi" CssClass="txtBox" runat="server"></asp:TextBox>
</div>
<asp:Button ID="save" runat="server" CssClass="UniversalBtn" OnClick="btnCheck_Click" />
<asp:Button ID="cancel" runat="server" CssClass="UniversalBtn" OnClick="btnCancel_Click" />
<asp:Button ID="edit" runat="server" CssClass="UniversalBtn" />
<asp:Button ID="submit" runat="server" CssClass="BtnSubmit" OnClick="btnSubmit_Click" Text="DONE"/>
</div>
</form>
</body>
</html>
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GMode.tiz
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCheck_Click(object sender, EventArgs e)
{
lbl.CssClass = "done";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
lbl.CssClass = "undone";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (hi.Text == "")
{
lbl.Text = "No Value";
}
else
{
lbl.Text = hi.Text;
}
}
}
}
So basically I want to dynamically create <div class="singleContainer"> with everything inside it x times (x defined by the user).
I'm going about this more on the fact like it's C++. When you can dynamically create an array with a specific number x.
Please tell me if you need more of the code. There are still the css and js files that I did not post.
Thank you,
Jack
I think that for this the best option is to use AngularJS, you can do something like this:
<html>
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-resource.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.min.js"></script>
<script>
var app = angular.module('app', [])
app.controller('PostsCtrl', function ($scope) {
$scope.change = function (){
$scope.listDivs = [];
for(var i=0;i<$scope.createDiv;i++) {
$scope.listDivs.push(i);
}
}
})
</script>
</head>
<body ng-app='app'>
<div ng-controller='PostsCtrl' class='container'>
<input ng-model='createDiv' ng-change="change()"/>
<ul class='list-group'>
<li ng-repeat="post in listDivs" class='list-group-item'>
<div class="singleContainer">
<div class="lblPlace">
<asp:Label ID="lbl" runat="server" Text="Input Task"> </asp:Label>
<asp:TextBox ID="hi" CssClass="txtBox" runat="server"> </asp:TextBox>
</div>
<asp:Button ID="save" runat="server" CssClass="UniversalBtn" OnClick="btnCheck_Click" />
<asp:Button ID="cancel" runat="server" CssClass="UniversalBtn" OnClick="btnCancel_Click" />
<asp:Button ID="edit" runat="server" CssClass="UniversalBtn" />
<asp:Button ID="submit" runat="server" CssClass="BtnSubmit" OnClick="btnSubmit_Click" Text="DONE"/>
</div>
</li>
</ul>
</div>
</body>
</html>
Put your div into a usercontrol (ascx file).
In your main page add a placeholder:
<asp:PlaceHolder runat="server" ID="PlaceHolder1" />
in code behind you can add your control as often as you want:
yourControl= LoadControl("~/Controls/yourControl.ascx");
PlaceHolder1.Controls.Add(yourControl);
Control 'MainContent_forenameTxt' of type 'TextBox' must be placed inside a form tag with runat=server. [And similar errors]
This error has been bugging me for a few days now. I've narrowed the problem down to an issue being within my Master Page.
For some reason, ASP TextBoxes, Buttons etc.. require to be in a form (Which shouldn't necessarily be the case) however my Program decided that it wants to be.
So, this issue began when I placed the forms in, stating I could only have one with a runat="server". After much googling and questioning I was given this piece of code:
public override void VerifyRenderingInServerForm(Control Control)
{
//base.VerifyRenderingInServerForm(Control);
}
Which, from what I can see, does absolutely nothing. It never gets called, and has nothing in it, however makes the page display - so I have absolutely no idea what it does.
So continuing on, it began to bug me, then I realised that my Buttons weren't actually doing anything, except 'refreshing' the page essentially. (Refer to near the bottom of page, with the onClicks
<%# Page Title="Registration" Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.Master" CodeFile="registration.aspx.cs" Inherits="registration" %>
<div class="contact-bg2">
<div class="container">
<div class="booking">
<h3>Register</h3>
<p>
</p>
<div class="col-md-8 booking-form">
<h5>Forename</h5>
<asp:TextBox ID="forenameTxt" runat="server"></asp:TextBox>
<h5>Surname</h5>
<asp:TextBox ID="surnameTxt" runat="server"></asp:TextBox>
<h5>Telephone</h5>
<asp:TextBox ID="telephoneTxt" runat="server"></asp:TextBox>
<h5>Mobile</h5>
<asp:TextBox ID="mobileTxt" runat="server"></asp:TextBox>
<h5>Address</h5>
<asp:TextBox ID="addressLn1Txt" placeholder="Line 1" runat="server"></asp:TextBox>
<asp:TextBox ID="addressLn2Txt" placeholder="Line 2" runat="server"></asp:TextBox>
<asp:TextBox ID="addressLn3Txt" runat="server" placeholder="Line 3"></asp:TextBox>
<h5>Postal Code</h5>
<asp:TextBox ID="postalTxt" runat="server"></asp:TextBox>
<h5>Username</h5>
<asp:TextBox ID="registerUsernameTxtbox" runat="server"></asp:TextBox>
<h5>Password Confirm Password</h5>
<asp:TextBox ID="registerPasswordTxtbox" runat="server" type="password"></asp:TextBox>
<asp:TextBox ID="passwordConfirmTxt" runat="server" type="password"></asp:TextBox>
<h5></h5>
<asp:Button ID="submitBtn" runat="server" Text="SUBMIT" OnClick="submitBtn_Click" />
<asp:Button ID="resetBtn" runat="server" Text="RESET" OnClick="resetBtn_Click" />
</div>
</div>
</div>
</asp:Content>
Code Behind:
protected void submitBtn_Click(object sender, EventArgs e)
{
//If there is any blank fields, these if statements will be run.
try
{
//If the fields entered have all had an input, this if statement will submit it to the database.
if (forenameTxt.Text != "" && surnameTxt.Text != "" && telephoneTxt.Text != "" && addressLn1Txt.Text != "" && addressLn2Txt.Text != "" && postalTxt.Text != "" && registerUsernameTxtbox.Text != "" && registerPasswordTxtbox.Text != "" && passwordConfirmTxt.Text != "")
{
DLQueries reposit = new DLQueries();
//Refers to 'addCustomerAccount' in droversLodgeRepository
reposit.addCustomerAccount(registerUsernameTxtbox.Text.ToString(),
registerPasswordTxtbox.Text.ToString(), forenameTxt.Text.ToString(),
surnameTxt.Text.ToString(), mobileTxt.Text.ToString(), telephoneTxt.Text.ToString(),
addressLn1Txt.Text.ToString(), addressLn2Txt.Text.ToString(),
addressLn3Txt.Text.ToString(), postalTxt.Text.ToString());
//Redirects to homepage
}
else
{
Response.Redirect("homepage.aspx");
}
}
catch (Exception)
{
}
}
protected void resetBtn_Click(object sender, EventArgs e)
{
forenameTxt.Text = "";
surnameTxt.Text = "";
telephoneTxt.Text = "";
addressLn1Txt.Text = "";
addressLn2Txt.Text = "";
postalTxt.Text = "";
registerUsernameTxtbox.Text = "";
registerPasswordTxtbox.Text = "";
passwordConfirmTxt.Text = "";
}
Now from that alone, I never saw any issues (unless someone else can see any).
So now, I assumed that the issue is on the masterpage. I've went through the masterpage, comparing it with an old website I built and couldn't find the issue.
Head:
<head id="Head1" runat="server">
<title>Page.Title</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Pinyon+Script' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Quicksand:400,700' rel='stylesheet' type='text/css'>
<link href="css/bootstrap.css" rel='stylesheet' type='text/css'/>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery.min.js"></script>
</head>
Body:
<body>
<div class="header">
<div class="top-header">
<div class="container">
<div class="logo">
<img src="images/logo.png"/>
</div>
<span class="menu"> </span>
<div class="m-clear"></div>
<div class="top-menu">
<ul>
<li class="scroll">HOME</li>
<li><a class="scroll" href="facilities.aspx">FACILITIES</a></li>
<li><a class="scroll" href="pricing.aspx">PRICS</a></li>
<li><a class="scroll" href="contactUs.aspx">CONTACT US</a></li>
</ul>
<script>
$("span.menu").click(function () {
$(".top-menu ul").slideToggle(200);
});
</script>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<div id="body">
<asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
<section class="content-wrapper main-content clear-fix">
<asp:ContentPlaceHolder runat="server" ID="MainContent" >
</asp:ContentPlaceHolder>
</section>
</div>
</>
<!---->
<div class="fotter">
<div class="container">
<h3>143 City Located Hotels World Wide</h3>
<h4>"Hospitality, Quality & Good Locations. We only provide you with the best hotels" - John Deo</h4>
<i class="man"></i>
</div>
</div>
<!---->
<div class="fotter-info">
<div class="container">
<div class="col-md-5 details">
<div class="hotel-info">
<h4>ABOUT THIS HOTEL</h4>
<p>This hotel is a 4 Star Hotel found on the Isle of Mull, in Scotland. </p>
<p><b>In order to book for this hotel, you will require to create an account online!</b></p>
</div>
<div class="news">
<h4>LATEST NEWS</h4>
<h5>Grand Hotel Joins DeluxelHotels</h5>
15 AUG
<h5>Happy Chirstmas To Everyone</h5>
15 AUG
<h5>Best Places To Visit 2014</h5>
15 AUG
<h5>Various Offers</h5>
15 AUG
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-7 details">
<div class="join">
<h4>JOIN DELUXEHOTELS</h4>
<p>
TBA
</p>
<p>TBA</p>
READ MORE
</div>
<div class="member">
<h4>MEMBERS AREA</h4>
<form id="Form1" runat="server">
<p>Username</p>
<asp:textbox id="txtUsername" runat="server"></asp:textbox>
<p>Password</p>
<asp:textbox id="txtPassword" textmode="Password" runat="server" />
<asp:button id="logoutBtn" runat="server" text="LOGOUT" visible="false" onclick="logoutBtn_Click" />
<asp:button id="loginBtn" runat="server" text="LOGIN" onclick="loginBtn_Click" />
<asp:button id="registerBtn" runat="server" text="REGISTER" onclick="registerBtn_Click" />
</form>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</div>
</body>
Now just to add on as a side-note.
I'm currently using a BootStrap UI Template for my website. I've took highlights of pieces of code which would/could be causing the problem
Things that I have noticed/tried:
- Buttons on MasterPage work fine.
- Buttons on 'registration' page don't work (i.e reset and submit)
- The parameter on the registration page was too big, so placed all details in that method instead
- MasterPage MainContent - Placing a Form within this.
- Removing all forms
- Create a new testpage which doesn't use MasterPage (buttons do work)
- Compared with my other website
I'm no expert at fixing issues, and have struggled to find this error, which you'll most likely find much more quickly than myself.
I'd like to apologise for such a large issue/question, but I'd like to get this sorted and not repeat my problem again in the future.
Thanks for looking at this.
I never found the issue. However, I found a workaround until I can find a sufficient alternative.
I started a new Project in Visual Studio, and decided to pick out every piece of information which would be an absolute necessity for the Website to still look relatively decent, and work.
[This means, I have one form over a contentplaceholder, which is holding everything, including another contentplaceholder where the information from every other page is in that placeholder].
I am still getting a few of the errors (which are easily fixable), however the override class is now, not being used due to some debugging finds, I found that it was overriding the button onClicks.
while clicking on button it give me an error "System.NullReferenceException: Object reference not set to an instance of an object"
aspx Code
<body>
<form id="form1" runat="server">
<div id="choto">
</div>
<asp:Button ID="btn" runat="server" onclick="btn_Click" Text="Submit" />
</form>
</body>
JS code
<script type="text/javascript">
document.getElementById("choto").innerHTML = "<input name=txt1 type=\"text\" id=\"txt1\" ru" + "nat=\"server\" />";
</script>
C# code
protected void btn_Click(object sender, EventArgs e)
{
// HtmlInputText txt = new HtmlInputText();
HtmlInputText txt = (HtmlInputText)FindControl("txt1");
txt.Value = "Shakeel";
}
Simply put, the input with the id "txt1" is not an ASP.NET control, therefore ASP.NET cannot find it. ASP.NET controls must be defined on the server, or the framework won't know about them.
<body>
<form id="form1" runat="server">
<div id="choto">
<asp:TextBox ID="txt1" runat="server" style="display:none;" />
</div>
<asp:Button ID="btn" runat="server" onclick="btn_Click" Text="Submit" />
</form>
</body>
ASP.NET controls cannot be added via JavaScript, however, they can be made to be invisible/visible using JavaScript.
<script type="text/javascript">
document.getElementById('<%# txt1.ClientID %>').style.display = "block";
</script>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a Text box. On button click event the value of Text box should be displayed in a label as result.
On clicking the button again and giving some input in the Text box the input should get added to the result.
I mean repeating the button clicks and providing input should get added o the result.
How to perform this?
I am still getting error
"System.FormatException: Input string was not in a correct format."
Error is regarding: lblconsumed.Text = (int.Parse(lblconsumed.Text) + userValue).ToString();
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication1.ServRef;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
ServRef.ProteinServiceClient sc = new ServRef.ProteinServiceClient();
UserDetail userinfo = new UserDetail();
protected void Page_Load(object sender, EventArgs e)
{
// ddlUser.DataSource = sc.AddUser(userinfo);
BindUserDetails();
}
protected void BindUserDetails()
{
IList<UserDetail> objUserDetails = new List<UserDetail>();
//objUserDetails = objService.GetUserDetails("");
objUserDetails = sc.GetAllUser("");
ddlUser.DataSource = objUserDetails;
ddlUser.DataBind();
}
protected void btnAddUser_Click(object sender, EventArgs e)
{
userinfo.user_name = tbname.Text.Trim();
userinfo.user_goal = Convert.ToInt32(tbgoal.Text.Trim());
string result = sc.AddUser(userinfo);
lblgoal.Text = Convert.ToString(userinfo.user_goal);
}
protected void Button2_Click(object sender, EventArgs e)
{
int userValue;
if (int.TryParse(tbamount.Text, out userValue))
{
lblconsumed.Text = (int.Parse(lblconsumed.Text) + userValue).ToString();
}
}
}
}`
My aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Style.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div id="main">
<h2>Protein Tracker</h2>
<div id="selectuser">
<label for="select-users">Select a user : </label>
<asp:DropDownList ID="ddlUser" runat="server"
Width="60px" AutoPostBack="True"
DataTextField="user_name"
DataValueField="user_name" ></asp:DropDownList>
</div>
<hr />
<div id="adduser">
<h2>Add new user</h2>
<label for="name">User Name :</label>
<asp:TextBox ID="tbname" runat="server" style="margin-left: 10px"></asp:TextBox>
<br /><br />
<label for="goal">User Goal :</label>
<asp:TextBox ID="tbgoal" runat="server" style="margin-left: 20px"></asp:TextBox>
<br /><br />
<asp:Button ID="btnAddUser" runat="server" Text="Add" style="margin-left: 210px" OnClick="btnAddUser_Click" />
</div>
<hr />
<div id="addprotein">
<h2>Add protein</h2>
<label for="amount">Amount :</label>
<asp:TextBox ID="tbamount" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Add" style="margin-left: 180px" OnClick="Button2_Click"/>
</div>
<hr />
<div>
<p>Total Consumed :  <asp:Label ID="lblconsumed" runat="server" Text=""></asp:Label></p>
<p>Goal Set :  <asp:Label ID="lblgoal" runat="server" Text=""></asp:Label></p>
</div>
</div>
</form>
</body>
</html>
#user3174595 : I have put in the simple code. its the easiest operation that can be performed.
form1.aspx
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="0" ></asp:Label>
</div>
</form>
form1.aspx.cs
public partial class addition : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
double userValue = 0;
if (double.TryParse(TextBox1.Text,out userValue))
{
Label1.Text = (double.Parse(Label1.Text) + userValue).ToString();
}
}
}
I've absolutely exhausted Google and I can't find a solution to this problem. When click a button on my .aspx page, the corresponding function is not called from .aspx.cs file. I'll just post my code and see if there are any takers.
AddUser.aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="AddUser.aspx.cs" Inherits="AddUser" %>
<asp:Content ID="tb_AddUserHeader" ContentPlaceHolderID="tb_HeaderPlaceHolder" Runat="Server">
</asp:Content>
<asp:Content ID="tb_AddUserContent" ContentPlaceHolderID="tb_ContentPlaceHolder" Runat="Server">
<h1>Add User</h1>
<fieldset>
<asp:Label ID="tb_lblAddUser_Authorized" runat="server" Visible="false">
<br />
<table>
<tr>
<td><u>Username:</u></td>
<td><asp:TextBox ID="tb_txtbxUsername" runat="server" Width="200"></asp:TextBox></td>
</tr>
<tr>
<td><u>Password:</u></td>
<td><asp:TextBox ID="tb_txtbxPassword" runat="server" Width="200" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td><u>Account Type:</u></td>
<td><asp:DropDownList ID="tb_ddAccountType" runat="server">
<asp:ListItem Value="v" Text="Viewer"></asp:ListItem>
<asp:ListItem Value="t" Text="Tester"></asp:ListItem>
<asp:ListItem Value="a" Text="Admin"></asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td><asp:Button ID="tb_btnAddUserSubmit" runat="server" Text="Submit" OnClick="tb_btnAddUserSubmit_Click" UseSubmitBehavior="true" /></td>
</tr>
</table>
<br />
</asp:Label>
<asp:Label ID="tb_lblAddUser_Output" runat="server" Visible="false"></asp:Label>
<asp:Label ID="tb_lblAddUser_Unauthorized" runat="server" Visible="true">
<br />Only administrators are authorized to view this page
<br />
<br />
</asp:Label>
</fieldset>
</asp:Content>
and my corresponding codebehind file, AddUser.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using tbBusinessObjects;
using tbWebClientControllers;
public partial class AddUser : System.Web.UI.Page
{
tbWebUserController m_userController;
protected void Page_Load(object sender, EventArgs e)
{
m_userController = new tbWebUserController();
//if (this.IsPostBack)
//{
// String username = tb_txtbxUsername.Text;
// //tb_btnAddUser_Click(sender, e);
//}
//else
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
if (ticket.UserData == "a")
{
tb_lblAddUser_Authorized.Visible = true;
tb_lblAddUser_Unauthorized.Visible = false;
}
}
}
}
protected void tb_btnAddUserSubmit_Click(object sender, EventArgs e)
{
tbUser user = new tbUser();
user.m_username = tb_txtbxUsername.Text;
user.m_password = tb_txtbxPassword.Text;
user.m_type = tb_ddAccountType.SelectedValue.ToCharArray()[0];
if (m_userController.InsertUser(user))
{
tb_lblAddUser_Output.Text = "<br />User was successfully added<br /><br />";
}
else
{
tb_lblAddUser_Output.Text = "<br />There was an error adding user<br /><br />";
}
tb_lblAddUser_Output.Visible = true;
tb_lblAddUser_Authorized.Visible = false;
}
}
I've set multiple breakpoints in my Click function and they're never hit. I tried simply catching my Page_Load function with a Page.IsPostBack, but it none of the data is saved from the textboxes or dropdown.
I've also tried changing the UseSubmitBehavior tag between true and false and removing it completely and it still doesn't work. I've copy/pasted as much code from other pages that use button events that are working and it still won't work. I have absolutely no idea what is going on right now. >_<
EDIT: And just in case it would help in any way, here is my Site.master...
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head id="tb_head" runat="server">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>KersTech Hydraulic/Electric Hybrid Data Recording and Telemetry</title>
<link href="tb_style.css" rel="stylesheet" type="text/css" media="screen" />
<asp:ContentPlaceHolder id="tb_HeaderPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="tb_formBody" runat="server">
<!-- Begin wrapper -->
<div id="tb_wrapper">
<asp:Label ID="tb_lblFormsAuthenticationUserData" runat="server" Text="Nothing" Visible="false"></asp:Label>
<!-- Begin top -->
<div id="tb_top">
<ul id="tb_nav">
<asp:Label ID="tb_lblMasterMenu" runat="server"></asp:Label>
<li><asp:LoginStatus ID="tb_LoginStatus" runat="server" LogoutAction="Redirect" LogoutPageUrl="Logout.aspx" /></li>
</ul>
<div id="tb_Greeting">
<asp:LoginView ID="tb_MasterLoginView" runat="server">
<LoggedInTemplate>
Logged in as <asp:LoginName ID="MasterLoginName" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
</div>
<asp:Label ID="test" runat="server"></asp:Label>
</div>
<!-- Begin content -->
<div id="tb_content">
<asp:ContentPlaceHolder id="tb_ContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
<!-- End content -->
<!-- Begin footer -->
<div id="tb_footer"><div id="something">
<!-- Begin badges -->
<div>
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /> <!-- HTML validation badge -->
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /> <!-- CSS validation badge -->
</a>
</div></div>
<!-- End badges -->
</div>
<!-- End footer -->
</div>
<!-- End wrapper -->
</form>
</body>
</html>
EDIT2: I moved my Button outside of my label and manually set the button's visibility along with the label's visibility (that was the only reason I was using those labels in the first place), and it worked just fine. I just spent the last hour and a half trying to figure this out, so in case anyone else ever has the same issue again:
ASP:BUTTONs WILL NOT FIRE FROM INSIDE OF ASP:LABELs!!!!!
try butting this line in the page load
tb_btnAddUserSubmit.Click += new EventHandler(tb_btnAddUserSubmit_Click);
I think the problem may be that the click handler is not register in the click event
Have you copied this method from other page/application ? if yes then it will not work, So you need to delete the event and event name assigned to the button then go to design and go to button event properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button. this should work
Try AutoEventWireup="false" in your page headers. I haven't worked in ASP.net in like 5 years but I remember that would sometimes break stuff.
I cannot find your tb_btnAddUserSubmit declaration in .cs code behind, and the handler.
You need to have a AddUser.Designer.cs class. Make sure to check that.
You also need to register the event in OnInit, instead of Page_load.