|
Not seeing the whole piece of code ... it looks like you are try to reference a column called, "reryattempts", maybe from a datarow and that column does not exist.
Try something like dr.items.count to see how many columns are present.
|
|
|
|
|
Thanks for your response! Here is the entire code.
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("sp_AuthenticateUser", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramUsername = new SqlParameter("@Username", username);
SqlParameter paramPassword = new SqlParameter("@Password", password);
cmd.Parameters.Add(paramUsername);
cmd.Parameters.Add(paramPassword);
con.Open();
// int ReturnCode = Convert.ToInt32(cmd.ExecuteScalar());
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
int RetryAttempts = Convert.ToInt32(rdr["RetryAttempts"]);
if (Convert.ToBoolean(rdr["AccountLocked"]))
{
lblMessage.Text = "Account is locked. Please contact your Web Administrator!";
}
else if (RetryAttempts > 0)
{
int AttemptsLeft = (4 - RetryAttempts); // allow 4 attempts
lblMessage.Visible = true;
lblMessage.Text = "Invalid username and/or password. " +
AttemptsLeft.ToString() + " attempt(s) left";
}
else if (Convert.ToBoolean(rdr["Authenticated"]))
{
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, chk_Remember.Checked);
Response.Redirect("../index.aspx");
}
}
}
|
|
|
|
|
|
If you're getting an IndexOutOfRangeException on the line int RetryAttempts = Convert.ToInt32(rdr["RetryAttempts"]); , that means your query is not returning a column called "RetryAttempts".
You'll need to examine your stored procedure to see what columns it's actually returning, and either fix the column name in your code, or fix the column name in your stored procedure.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for telling me to check my stored procedure. I discovered there is a typo in my stored procedure. I had it as "RetyAttempts".
Million Thanks! Merry Christmas!!
|
|
|
|
|
Lay_Kay wrote: System.IndexOutOfRangeException: RetryAttempts The message is telling you that the value in RetryAttempts (which is a different variable than retryattempts ) does not contain a valid index for the list or array that it references. We need to see the code where the error occurs.
|
|
|
|
|
Greetings again,
I am really struggling to get my code to work.
have a gridview with ID = Gridview1.
This gridview has three textboxes and one checkbox with id = grid1Details
The requirements:
if => checkbox is unchecked and textboxes are empty => You cannot submit your form
if => checkbox is checked and textboxes are empty => You can submit your form
if => checkbox is unchecked and textboxes are not empty => You can submit your form
By default, upon page load, checkbox is unchecked and textboxes are enabled.
How do I modify the following code to make this work?
Protected Sub Grid1CheckChanged(ByVal sender As Object, ByVal e As EventArgs)
'Dim hasBlank As Boolean = False
For Each row As GridViewRow In Gridview1.Rows
Dim ename As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox)
Dim empaddress As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox)
Dim empincomesrc As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox)
Dim sourceCheck As CheckBox = DirectCast(Gridview1.FindControl("grid1Details"), CheckBox)
If Not sourceCheck.Checked Then
'hasBlank = True
ename.Enabled = True
empaddress.Enabled = True
empincomesrc.Enabled = True
ElseIf Not sourceCheck.Checked And ename.Text Is Nothing And empaddress.Text Is Nothing And empincomesrc.Text Is Nothing Then
lblStatus.Text = "Please either fill out the textboxes or check the checkbox."
Else
ename.Enabled = False
empaddress.Enabled = False
empincomesrc.Enabled = False
End If
Next
End Sub
JavaScript would probably be better but my attempt at using JavaScript has not worked so far.
Below is my attempt at javascript:
<script type="text/javascript">
function ValidateTextBox() {
checkbox = document.getElementById("grid1Details");
var textvalue = $(".textClass").attr('value');
if (!checkbox.checked && textvalue != "") {
alert("Either check the box or enter value in all textboxes.");
return false;
}
return true;
}
</script>
//markup:
<td> <asp:Button ID="btnNext" CssClass="btnNext" runat="server" Text="Review Form" OnClientClick="BtnClick();javascript:return ValidateTextBox();" OnClick="btnNext_Click" /></td>
<table>
<tr>
<td>
<asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<headerstyle horizontalalign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtsourcename" CssClass="textClass" placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:250px;" class="form-control"></asp:TextBox><br />
<asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span style="color:#ff0000">*Check this box if N/A</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceaddress" CssClass="textClass" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox><br /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceincome" CssClass="textClass" placeholder="Income...(example: 1000)" runat="server" style="width:250px;" class="form-control txtsourceincome numeric"></asp:TextBox><br /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add"
onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();return validate()" /><br /><br /><br>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
CssClass="grvDelButton" OnClientClick="return confirm('are you sure?')" /> <br /><br /><br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
</table>
Thanks in advance
modified 18-Dec-17 15:01pm.
|
|
|
|
|
Hi,
I am creating an Asp.Net MVC5 application where I have two areas called Teacher and Parent. I want to display a Child's home page based on the area, that is, both the teacher and parent have their own page layout. I can pull the child data using json. How can display it as a partial view in both parent and teacher home page?
Thanks
|
|
|
|
|
I find many discussions, but none work with more div
<pre><script type="text/javascript">
window.onload = function scr1() {
var div = document.getElementById("dvScroll");
var div_position = document.getElementById("div_position");
var position = parseInt('<%=!string.IsNullOrEmpty(Request.Form["div_position"]) ? Request.Form["div_position"] : "0" %>');
div.scrollTop = position;
div.onscroll = function () {
document.getElementById("div_position").value = div.scrollTop;
};
};
</script>
<pre> <form id="form1" runat="server">
<div id="dvScroll"; style="width:450px; height:300px; overflow:scroll; float:left">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CellPadding="4">
<Columns>
<asp:BoundField DataField="ID_NAVE" HeaderText="IdNave" ItemStyle-Width="50" ItemStyle-wrap="false" Visible="true" />
....
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="div_position" name="div_position" />
the DIV dvscroll with the HiddenField
<pre><form id="form1" runat="server">
<div id="dvScroll"; style="width:450px; height:300px; overflow:scroll; float:left">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CellPadding="4">
<Columns>
<asp:BoundField DataField="ID_NAVE" HeaderText="IdNave" ItemStyle-Width="50" ItemStyle-wrap="false" Visible="true" />
....
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="div_position" name="div_position" />
<div id="dvScroll2"; style="clear:both; width:600px; height:300px; overflow:scroll;">
<asp:HiddenField ID="HiddenField2" runat="server" />
<asp:GridView ID="GridMnuRest" runat="server" AutoGenerateColumns="false" CellPadding="4" OnRowCreated="GridMnuRest_RowCreated" OnRowDataBound="GridMnuRest_RowDataBound" OnSelectedIndexChanged="GridMnuRest_SelectedIndexChanged" OnSelectedIndexChanging="GridMnuRest_SelectedIndexChanging" OnRowCommand="GridMnuRest_RowCommand">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="MnuSelect" runat="server" AutoPostBack="true" OnCheckedChanged="GridMnuRest_OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id_ristorante" HeaderText="IdRst" ItemStyle-Width="20" ItemStyle-wrap="false" Visible="true" />
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="div_position2" name="div_position2" />
</form>
as you can do for 2 or more DIV ?
|
|
|
|
|
|
The post script with only one div works, but you can do it better and make it easier to manage.
The new solution
combination with ScriptManager and UpdatePanel components.
1) create a DIV at level Body
2) create script reference for WebForm.js
3) create a DIV for GridView
4) add a UpdatePanel
5) declare structure GridView
important, without update panel the position after a Postback is not maintained
<body style="height: 857px">
<form id="form1" runat="server">
<!-- General DIV for page -->
<div>
<!-- Script Manager -->
<asp:ScriptManager ID="ScriptManager2" runat="server">
<Scripts>
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
</Scripts>
</asp:ScriptManager>
<!-- DIV for Grid master -->
<div id="dvScroll"; style="width:450px; height:300px; overflow:scroll; float:left">
<!-- UpdatePanel for UpdatePostback -->
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<!-- Grid Master -->
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CellPadding="4" OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ID_NAVE" HeaderText="IdNave" ItemStyle-Width="50" ItemStyle-wrap="false" Visible="true" />
<asp:BoundField DataField="NOMENAVE" HeaderText="nave" ItemStyle-Width="15" ItemStyle-wrap="false" Visible="true" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
for other GrdiView , is the same
<pre> <div style="width:450px; float:left; height:300px; overflow:scroll;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:GridView ID="GridRest" runat="server" AutoGenerateColumns="false" CellPadding="4" OnRowCreated="GridRest_RowCreated" OnRowDataBound="GridRest_RowDataBound" OnSelectedIndexChanged="GridRest_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="id_restaurant" HeaderText="IdRst" ItemStyle-Width="50" ItemStyle-wrap="false" Visible="true" />
<asp:BoundField DataField="restaurantname" HeaderText="Restaurant" ItemStyle-Width="15" ItemStyle-wrap="false" Visible="true" />
<asp:BoundField DataField="suite" HeaderText="Suite" ItemStyle-Width="100" ItemStyle-wrap="false" Visible="true" />
</Columns>
<HeaderStyle BackColor="gray" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
|
|
|
|
|
Hi all,
I need help about this problem:
I call from a wcf service another web service (a soap web service).
Now I receive following error message:
The content type application/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:
<?xml version=\"1.0\"?>\n<definitions xmlns=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"http://xxx.xx.xxx.xxx/ws/servicexx/xx/web/xxxx/index?ws=1\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" name=\"xx.xxx.xx.xxcontrollers.xxxxController\" [...]
I'm wrong or it seems wsdl ?
This is not the soap response.
I think that could be a mismatch between server and client (my wcf service) configuration.
Could you help me ?
Thanks in advance.
|
|
|
|
|
|
Thankyou for your answer.
I have already read these articles, but in any case, about my "target" web service, I have only a url and I can browse it. I have no more informations.
I have generated a interface and types using svcutil.
The web service address is like the following one
http://123.11.321.111/room/web/webMethods ( no extension like .svc or .asmx).
The soap action in the wsdl : soapAction="http://123.11.321.111/room/web/webMethods/index?ws=1
I tried also to create a new Console Application and call it by a web reference. Only in that situation I can receive the right response.
The Console Application app.config has a basicHttpBinding configuration.
It is possible that I'm not facing a soap service as I expect and instead it is a REST service ?
How can I figure out this for sure ? (more or less the problem that is described in first article)
Wouldn't I have the same problems with the Console Application ?
modified 18-Dec-17 11:56am.
|
|
|
|
|
The start of the response definitely looks like it comes from a SOAP service.
This SO thread[^] suggests it could be a version mismatch between the server and the client. SOAP 1.2 (WSHttpBinding ) uses application/soap+xml , whereas SOAP 1.1 (BasicHttpBinding ) uses text/xml .
You'll probably need to talk to whoever wrote the service to make sure your bindings match the server's bindings.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How to fix error "the type or namespace name 'CustomerBAL' could not be found (are you missing a using directive or an assembly reference)
Name project MvcApplication1) on ASP.Net Visual Studio 2012
Could anyone help me ? Thank's in advance ...
|
|
|
|
|
|
I am sorry..Have a trouble with my internet connection
|
|
|
|
|
see the sample code
This is books model
-----------------------
public class Book
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(30)]
public string Title { get; set; }
public string Authers { get; set; }
[Column("Year")]
[Display(Name = "Publish Year")]
public string publishYear { get; set; }
[Column("Price")]
[Display(Name = "Price")]
public decimal BasePrice { get; set; }
}
Repository interface
--------------------
public interface IBookRepository : IDisposable
{
IEnumerable<Book> GetBooks();
Book GetBookByID(int bookId);
void InsertBook(Book book);
void DeleteBook(int bookID);
void UpdateBook(Book book);
void Save();
}
Book repository
--------------------
public class BookRepository : IBookRepository
{
private BookContext _context;
public BookRepository(BookContext bookContext)
{
this._context = bookContext;
}
public IEnumerable<book> GetBooks()
{
return _context.Books.ToList();
}
public Book GetBookByID(int id)
{
return _context.Books.Find(id);
}
public void InsertBook(Book book)
{
_context.Books.Add(book);
}
public void DeleteBook(int bookID)
{
Book book = _context.Books.Find(bookID);
_context.Books.Remove(book);
}
public void UpdateBook(Book book)
{
_context.Entry(book).State = EntityState.Modified;
}
public void Save()
{
_context.SaveChanges();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
_context.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
code taken from https://www.codeproject.com/Articles/644605/CRUD-Operations-Using-the-Repository-Pattern-in-MV
now tell me when i will fetch books then how could i do the pagination...say want to retrieve 20 books or
i like to mention author name and 20 records when fetching book.
please help me with sample code. thanks
|
|
|
|
|
Two obvious options:
1) Have GetBooks return IQueryable<Book> :
public IQueryable<Book> GetBooks()
{
return _context.Books;
}
...
int pageIndex = 2;
int pageSize = 20;
IEnumerable<Book> pageOfBooks = repository.GetBooks().Skip(pageIndex * pageSize).Take(pageSize).ToList();
Some people don't like that, because it exposes the underlying database to the next layer up. But it works.
2) Have overloads of GetBooks to take the paging details:
public IEnumerable<Book> GetBooks()
{
return _context.Books.ToList();
}
public IEnumerable<Book> GetBooks(int pageIndex, int pageSize)
{
return _context.Books.Skip(pageIndex * pageSize).Take(pageSize).ToList();
}
...
int pageIndex = 2;
int pageSize = 20;
IEnumerable<Book> pageOfBooks = repository.GetBooks(pageIndex, pageSize);
This initially looks cleaner, but it doesn't let you sort the books before paging them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks you so much for a great answer.
I am new in EF. i often use ADO.Net
please tell me does the below line fetch all data from db and then apply pagination or the below code will fetch 20 records only from db?
IEnumerable<book> pageOfBooks = repository.GetBooks().Skip(pageIndex * pageSize).Take(pageSize).ToList();
Thanks
|
|
|
|
|
It will only get 20 records from the database but you'd have to examine the sql produced to examine how efficient it might be, especially if you have a lot of books.
|
|
|
|
|
If you change GetBooks to return IQueryable<Book> , then it will only retrieve 20 books from the database.
If it's still returning IEnumerable<Book> , then it will retrieve all books from the database, and then apply the pagination in-memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am new in EF.
so you said if i use
IEnumerable<book> then it will return all books and store in memory but if i use
IQueryable<Book> then it return 20 books from db.
public IEnumerable<book> GetBooks()
{
return _context.Books.ToList();
}
say if i wrote the getbook function like this way
public IQueryable<Book> GetBooks()
{
return _context.Books.ToList();
}
here IQueryable<book> GetBooks() return ToList() and when we are calling then we mention pagination like
IEnumerable<Book> pageOfBooks = repository.GetBooks().Skip(pageIndex * pageSize).Take(pageSize).ToList()
so .ToList() is using twice. one IQueryable<book> GetBooks() return .ToList() and other one when we are calling GetBooks()........will it have any side effect for using .ToList() ? i mean there will be any performance issue ?
please let me know and tell me does it have any performance issue if we use .ToList() twice ?.
|
|
|
|
|
Mou_kol wrote:
public IQueryable<Book> GetBooks()
{
return _context.Books.ToList();
}
First of all, that code won't compile. The List<T> class does not implement the IQueryable<T> interface.
You could make it compile by adding .AsQueryable() after .ToList() ; but that would defeat the point. The entire table would still be loaded into memory.
In order to load just a single page of books from the database, you would need to use the method I showed you previously:
public IQueryable<Book> GetBooks()
{
return _context.Books;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|