|
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
|
|
|
|
|
You've got no onclick event on the imagebutton itself. Easiest way is to double click it in your VS designer as this'll generate the blank method for you and put you into the .cs/.vb/.whatever codebehind you're using.
Downside: It'll postback your page which should stop your popup. What are you trying to achieve exactly?
|
|
|
|
|
You can't really open a pop-up and also do the server-side click event. The javascript click will add a div to the current document, the button click would fire which will trigger a request to your server code, which will run the server-side click event which will result in the document in the browser being replaced with the new document from the server so the div that your js added is now gone. You'll probably need to add code to the server-side click event of your button to create the pop-up when the document has finished rendering.
An Interactive jQuery Modal Popup Control for .NET[^]
|
|
|
|
|
Hello All,
I am new to the web technology, I would like to know, how can i call ASP.net Web Service in a HTML page using java script.
Any sample is appreciated.
Thanks in advance.
|
|
|
|
|
Go to www.asp.net[^] where you will find a wealth of information to get you started.
|
|
|
|
|
If you have some knowledge of JQuery, you can use the jQuery.ajax() function.
|
|
|
|
|
Hi All,
Thanks for your replies.
Struggled bit to use web service with JavaScript, and we are proceeded with WCF service, and succeeded in consuming the developed WCF service.
Consuming the web service in HTML page with JavaScript is still looking for the solutions.
Thank you.
|
|
|
|
|
With what are you struggling?
|
|
|
|
|
Hi Everyone
I am hoping someone can help me out. I have my pages setup as https://domain.com/about.aspx. My site works normal and everything is cool but I was not being indexed by Google. I checked a site and it confirmed I have a url error so when someone types in https://domain.com/about.aspx/
my site comes up with all the images missing but all the text there.
Does anyone know why?? I am assuming the correct response should be a 404 or the aspx work.
Hoping someone can help!
Thanks T
|
|
|
|
|
The server may be returning 404's for the images, but that is not how the browser will render it. It will simply show those placeholder "X" images.
You need to look at the img tags in your about.aspx document and make sure they have the correct URL's.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Looks like my developer does not have the backslash on the anything so for example /images/image1.png rather images/image1.png. This is for everything not just the images but href, etc..
So to be sure if you go to domain.com/about.aspx/ it should show the .aspx page again and not give a 404??
Thanks T
|
|
|
|