|
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
|
|
|
|
|
We have a form on our intranet site that employees must complete yearly.
To complete this form, employee must first enter his/her employee ID.
This ID is checked to see if this employee has completed this form before.
For instance, if this employee completed this form in the year 2016 but has not completed it in the year 2017, then his/her existing info (name, email, title) are pulled and are populated into their respective textboxes with a message that says, "Proceed"
If the employee has completed the current year of 2017, again, his/her information is pulled from employee table and populated into the textboxes so they don't have to enter those information again.
This time, the employee gets a message, "You have already completed this form"
If however, the employee has never completed this form, then the textboxes containing employee's info (name, email, title) are blank with a message, "Proceed"
So far, the only solution that seems to work is when employee has completed the form for the current year because the employee gets a message, "You have already completed the form".
How should I modify this to work in the other two situations where employee has completed previous year but has not completed the current year and employee has not never completed the form before?
Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
If Not String.IsNullOrEmpty(txtEmpID.Text) Then
Dim Conn As SqlConnection
'Read in connection String
Conn = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Conn.Open()
Dim cmd As New SqlCommand("select * from Employees e inner join dateDetails d on e.employeeID = d.EmployeeID where EmpID=@empID and Year(d.enterDate) >= 2016 and Year(d.enterDate)<= 2017", Conn)
cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
checkusername.Visible = True
'imgstatus.ImageUrl = "images/NotAvailable.jpg"
lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(100)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
Else
dr.Read()
checkusername.Visible = True
'imgstatus.ImageUrl = "images/Icon_Available.gif"
lblStatus.Text = "Proceed"
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(100)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
End If
Else
checkusername.Visible = False
End If
End Sub
|
|
|
|
|
I would imagine that you have a column in the database design that represents the "FORM_YEAR" and "FORM_STATUS"
When the form is completed the status of the "FORM_STATUS" changes to completed or true and the FORM_YEAR would be updated to 2018
If it ain't broke don't fix it
|
|
|
|
|
HI,
our office use VSS as source control. just come to know that VSTS is free for five user and our team is very small with 5 devs.
i have never use VSTS. so i have few questions. please answer point wise and with detail along with images if possible.
1) how to create a account for VSTS?
2) how to upload our local project exist in my pc to VSTS
3) how could i send invitation to other 4 developer in our team as a result they can clone our uploaded project in their own pc and start working ?
i got one link http://www.codeease.com/add-local-project-to-visual-studio-online.html which is showing how to Add Local Project to Visual Studio Online GIT but i need to know how to add to online TFS.
please guide me with sample images and details instruction. thanks
|
|
|
|
|
|
Not sure where to place this post.
I took the update a couple of days ago for VS2017 V15.5.0
My VS2017 was working fine for over a year and this update changed something, and I can't pinpoint it.
So I work on the old style MVC projects, where you have a Views, Controllers, etc. and the views went black and white, no intelisense.
Then on the create project, it no longer shows under website, MVC. It only shows Core.
The VS2017 installation always bombs on a DISM file called netfxextension-aspnet45 and says it doesn't exist.
I'm not sure if my VS2017 is broke or if my Win10 is broken.
Just wanted to see if anyone else has ran into this and a point in the right direction to fix it.
If it ain't broke don't fix it
|
|
|
|