|
Thank you for your sharing..
|
|
|
|
|
<asp:ImageButton ID="imgbtn_search" runat="server" BorderStyle="Solid" ImageUrl="~/images/search.png" style="height: 28px; position: relative; top: 11px; left: 934px; width: 30px;" OnClick="imgbtn_search_Click1"/>
<asp:TextBox ID="txt_search" placeholder="search by Machine and DD/MM/YYYY " runat="server" style="z-index: 1; left: 682px; top: 20px; position: absolute; width: 237px; bottom: 271px"></asp:TextBox>
modified 28-Sep-15 4:08am.
|
|
|
|
|
Simple, it submits your data. The "another page" would be the page where your form has to land after submission. Preventing the user from submitting a form via Enter key, is a bad UX, in my opinion. User would want to use keyboard for the submission process and you would be preventing him from doing so.
I have never used ASP.NET Web Forms, but I do know that even that form gets translated to HTML while rendering, so you can control that via JavaScript. Following script would suffice.
$('input[type="text"]').keydown(function (e) {
if(e.which == 13) {
return false;
}
});
This would do the trick for you, but I would suggest that you do not do so. Let user submit the form using Enter key.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you soo much for your kind answer.
what I actually mean is I created a search button. when I search for the result and press on ENTER, its going to default page. when I manually click on search button its showing the result.
|
|
|
|
|
We can't say from what you've posted. When you press enter in a textbox the first button of the form is clicked. So you'll need to find the first button on your form and try and work out from that what is happening. It could be clicking that button is activating js or something, we don't know.
|
|
|
|
|
Thank you soo much for your kind answer.
what I actually mean is I created a search button. when I search for the result and press on ENTER, its going to default page. when I manually click on search button its showing the result.
|
|
|
|
|
|
I tried that too, its work. Now the problem is I have 3 buttons in 1 panel. There are search, submit and log out. for the submit button I created as once insert data and click on submit button it will go to another page but when I use defaultbutton its remaining on the same page. because of that I did not use defaultbutton in panel.
Thank you
|
|
|
|
|
HI,
I want to know that,
What is the important of ISPostBack in asp.net???
Can AnyOne help???
|
|
|
|
|
|
IsPostBack is a property by which you can check that is your page is loading first time or postbacking.
In ASP.NET application every event (like clicking a button) causing postback of same page. So the code block written in the page load will execute every time.
If you does not want to execute it everytime then enclose that code block with a if(!IsPostBack){}.
PANKAJ MAURYA
SOFTWARE ENGINEER (Daffodil S/W)
Gurgaon
|
|
|
|
|
HI,
IQuote: IsPostBack is a Page level property, that can be used to determine whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.
example.
if(!ispostback){
}
else
{
}
When page response very first time then it go into if condition, after that your else statement will call always.
hi
|
|
|
|
|
This property is used to restrict the postback of page every time unnecessarily.
check like below in you code.
if(!IsPostback)
{
//this is your first visit.
}
else
{
//this is not your first visit.
}
Sridhar Thota.
|
|
|
|
|
I have a confusion here.
Both HtmlTextWriter and HtmlTable.RenderControl gives similar outputs then what is the difference considering the performance.
Thanks
|
|
|
|
|
|
Dear experts,
I do really appreciate your highly valued expertise.
I am trying to think up a solution but I am frozen.
First we have two tables ( I didn't design it in case it is flawed), Emp table and Angulers table.
The emp table contains the following fields:
EmpID,
EmpName
Password
Dept
And several others but those above are the relevant ones.
Then Angulers table with following relevant fieldnames:
EmpID - Foreign Key to Emp table
ManagerID -related to EmpID on Emp table
Status (Status has a value of Pending or Done)
The history:
The process is that employees will log in first to register their grievances and suggest a remedy.
Once an employee is done and clicks the Done button, next time that employee logs in, that employee is no longer allowed to make any changes.
By the way, employees log in with empID as username and Password as password.
This works fine.
Now that that employee is done, his or her manager then logs in to a page called EmployeeSummary.aspx to view a list of his/her employees.
Each manager can view his/her employee based on his/her ID and the department that s/he and his/her employees belong to.
This is where I am having problem.
How do I make a manager log into EmployeeSummary.aspx page and only see those employees that are in his/her department?
Here is the code I am working with but it is coming blank when I run it.
<div align="center">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPageIndexChanging" PageSize="10">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ManagerID,department"
DataNavigateUrlFormatString="employeeDetails.aspx?ID={0}&Dept={1}" Text="Add Comments" />
<asp:BoundField ItemStyle-Width="200px" DataField="empname" HeaderText="Employee Name" />
<asp:BoundField ItemStyle-Width="250px" DataField="department" HeaderText="Department" />
</Columns>
</asp:GridView>
</div>
--Code Behind:
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = '"&querystring("ID") & "' and e.department = '"&uerystring("dept") & "' ")
'We use parametized query to prevent sql injection attack
' Dim p1 As New SqlParameter("@dept", Session("dept"))
'cmd.Parameters.Add(p1)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
Protected Sub OnPageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
Me.BindGrid()
End Sub
Thank you in advance
|
|
|
|
|
Is this homework?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
|
Thank you very much Richard, as always.
You can see that I am actually using parametized query but commented it out just to get the code to work first before using it again.
|
|
|
|
|
You'll need to debug your code, apart from the typo (uerystring("dept")) we don't know what is wrong as we can't run your code in context, we don't know your inputs and we don't know your data. If it "doesn't work" then I suggest you examine the command you are building as querystring("ID") or querystring("dept") might not be what you think they are. If the manager ID is numeric then the issue might be that you're wrapping it in quotes which is only for text
"SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = "&querystring("ID") & " and e.department = '"&querystring("dept") & "' ")
|
|
|
|
|
I am really sorry guys.
I was showing wrong code.
The correction made by Richard is great and will be used on employeeDetails.aspx page.
However, where my issue lies on the current page.
We would like to show all records related to a department to be displayed when the manager of that department logs on to that page.
As a result, I am trying to use the managerId and department to filter the records.
I am trying to hide the managerId and department Id on the markup but use them to filter the records.
Currently, I am using just the department. If it works, I will add the manager but the department is not working.
Here is the department that I added to the gridview:
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
and I want to pass the value to the SELECT statement on codebehind.
Any ideas how to do this?
I will show the code again for clarity with some slight modifications:
<head>
<style type="text/css">
.dhide
{
display:none;
}
</style>
</head>
<div align="center">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPageIndexChanging" PageSize="10">
<Columns>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
<asp:HyperLinkField DataNavigateUrlFields="ManagerID,department"
DataNavigateUrlFormatString="employeeDetails.aspx?ID={0}&Dept={1}" Text="Add Comments" />
<asp:BoundField ItemStyle-Width="200px" DataField="empname" HeaderText="Employee Name" />
<asp:BoundField ItemStyle-Width="250px" DataField="department" HeaderText="Department" />
</Columns>
</asp:GridView>
</div>
'//Code behind:
<pre> Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = '"&querystring("ID") & "' and e.department = '"&uerystring("dept") & "' ")
'We use parametized query to prevent sql injection attack
' Dim p1 As New SqlParameter("@dept", Session("dept"))
'cmd.Parameters.Add(p1)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
|
|
|
|
|
Any data you want to store and get back on postback but you don't need to be a visible or editable field can be stored in the ViewState.
ViewState["DepID"] = id;
to read it after postback
int id = (int)ViewState["DepID"];
|
|
|
|
|
My question though is how do I grab the value of the following and:
<style type="text/css">
.dhide
{
display:none;
}
</style>
<asp:BoundField DataField="department">
<ItemStyle CssClass="dhide"/>
</asp:BoundField>
and pass it to the SELECT query on the BindGrid sub in codebehind and use it as filter like WHERE e.department = the value of dhide
How do I do that?
|
|
|
|
|
I never use binding like that I'm afraid, however rather than using a datagrid to "store" data (something you see a lot of) you should remember that it is simply there to *display* data. The grid is simply being bound to a datasource and if you want to read values then you should read them direct from the datasource you are binding the grid too rather than the grid itself.
It might be advisable to leave datagrids etc behind and use more basic mechanism like repeaters etc, and using the code-behind to bind your data rather than using auto-bound template fields. You end up with greater control over things.
|
|
|
|
|
Hi!
I was trying to open a Javascript pop up on click of button. Though I am able to open the pop up, but my problem is it does not file the onlclick event of the button.
---code for opening the pop up-----
<a href="#" title="Edit" style=" background-color:#FFF;" data-toggle="modal" data-target="#myModal1" style="background-color:#FFF;">
<asp:ImageButton id="imgedit" runat="server" ImageUrl="boot/img/pen2.png" CommandName="BtnEdit" style="width:20px; height:20px;"/></a>
------------------------------
My above code opens up the popup but the code written behind onclick event is not firing.
Please suggest how I can make my click event work and open the javascript popup
Thanks & Regards
|
|
|
|