Hyperlink

E

enak

I have put a HyperLink control on a page. When I click on
the link I am expecting the next page to display. However,
when I run it through the debugger I can see that the page
where the link resides is being processed again and the
link object is not set.

I have put "If not IsPostBack then" but IsPostBack is
False so the code gets executed again. Why is this
happening and how do I fix it?

Here is my code:

-- VB --
If Not IsPostBack Then
Me.lnkEdit.Target = "doc"
Me.lnkEdit.NavigateUrl = "CaseViewEdit.aspx?
CaseID=" & sCaseID
End If


-- ASP --
<asp:HyperLink id="lnkEdit" style="Z-INDEX: 161; LEFT:
321px; POSITION: absolute; TOP: 496px" runat="server" Font-
Size="X-Small" Font-Bold="True">Edit Current
Record</asp:HyperLink>

Any help would be appreciated.

Thanks
enak
 
M

Mike Moore [MSFT]

Hi Enak,

When you first browse a page, you ask for a fresh copy. This is called a
GET request. When ASP.NET processes a GET request, IsPostBack is false.
Later, you can submit the page with a button or link button (not a
hyperlink) to submit the form back to itself along with any data on the
page. This is called a POST request. When ASP.NET processes a POST request,
IsPostBack is true.

With a hyperlink, the page request is type GET. That means it's asking for
a fresh copy of the page and IsPostBack is false. If you want to set the
properties of the hyperlink during the post back, then you need to send a
request of type POST, such as with a button or link button.

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
M

Mike Moore [MSFT]

Hi Enak,

Pardon me, I misread your question. You did use NOT IsPostBack which is
correct.

When you submit a page with a button, it submits back to itself. Does your
hyperlink point back to itself?

I tried to reproduce your problem as follows:

* New page named Hyper1
* I put a hyperlink on it
* I added this to the code-behind load event
If Not IsPostBack Then
HyperLink1.NavigateUrl = "grid1.aspx?value=test"
End If

The result was that the hyperlink navigated to my other page named grid1
and it included the query string information.

What is the name of the page you are using for this hyperlink? Is it
CaseViewEdit.aspx? Or, is CaseViewEdit.aspx a separate page?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
From: (e-mail address removed) ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 09 Oct 2003 00:05:30 GMT
Subject: RE: Hyperlink
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi Enak,

When you first browse a page, you ask for a fresh copy. This is called a
GET request. When ASP.NET processes a GET request, IsPostBack is false.
Later, you can submit the page with a button or link button (not a
hyperlink) to submit the form back to itself along with any data on the
page. This is called a POST request. When ASP.NET processes a POST request,
IsPostBack is true.

With a hyperlink, the page request is type GET. That means it's asking for
a fresh copy of the page and IsPostBack is false. If you want to set the
properties of the hyperlink during the post back, then you need to send a
request of type POST, such as with a button or link button.

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "enak" <[email protected]>
Sender: "enak" <[email protected]>
Subject: Hyperlink
Date: Wed, 8 Oct 2003 06:20:54 -0700
Lines: 30
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcONnwBJvV2uP4hmSvGOUhFUQdI/fA==
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:15215
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

I have put a HyperLink control on a page. When I click on
the link I am expecting the next page to display. However,
when I run it through the debugger I can see that the page
where the link resides is being processed again and the
link object is not set.

I have put "If not IsPostBack then" but IsPostBack is
False so the code gets executed again. Why is this
happening and how do I fix it?

Here is my code:

-- VB --
If Not IsPostBack Then
Me.lnkEdit.Target = "doc"
Me.lnkEdit.NavigateUrl = "CaseViewEdit.aspx?
CaseID=" & sCaseID
End If


-- ASP --
<asp:HyperLink id="lnkEdit" style="Z-INDEX: 161; LEFT:
321px; POSITION: absolute; TOP: 496px" runat="server" Font-
Size="X-Small" Font-Bold="True">Edit Current
Record</asp:HyperLink>

Any help would be appreciated.

Thanks
enak
 
M

Mike Moore [MSFT]

Hi Enak,

I see you have another post that has more information. Here is a repeat of
what I posted to your other thread.

You wrote that all the other controls are available, but not the query
string or the hidden field.

1) Hidden field
When you use a hyperlink to get another page, the data in the page you are
leaving is lost. By comparison, when you use a button to submit the page
back to itself, then the data is posted along with the request to refresh
the page. So, you are losing the hidden field because you are using a
hyperlink to get a new page.

2) Query string
From what I can see, your query string should be working. Here is a sample
that you can try.

* I created two pages, Hyper1.aspx and Hyper2.aspx
* I added a hyperlink to Hyper1 and added this to its code-behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
HyperLink1.NavigateUrl = "Hyper2.aspx?value=test"
End If
End Sub

* I also added this to the code-behind for Hyper2.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Request.QueryString("value"))
End Sub

---
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights

--------------------
 
E

enak

mike thanks for your reply. The first page is called
CaseView.aspx. On that page is the hyperlink that points
to the page CAseViewEdit.aspx

IsPostBack comes back as FALSE. I don't know if this is
correct but I would think that it is because I should not
be posting to the first page.

All of the other links on the page work fine but then I am
using javascript to create a popup with those links.

Any ideas? I will try to redo the link, again.

Thanks
enak
-----Original Message-----
Hi Enak,

Pardon me, I misread your question. You did use NOT IsPostBack which is
correct.

When you submit a page with a button, it submits back to itself. Does your
hyperlink point back to itself?

I tried to reproduce your problem as follows:

* New page named Hyper1
* I put a hyperlink on it
* I added this to the code-behind load event
If Not IsPostBack Then
HyperLink1.NavigateUrl = "grid1.aspx? value=test"
End If

The result was that the hyperlink navigated to my other page named grid1
and it included the query string information.

What is the name of the page you are using for this hyperlink? Is it
CaseViewEdit.aspx? Or, is CaseViewEdit.aspx a separate page?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
From: (e-mail address removed) ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 09 Oct 2003 00:05:30 GMT
Subject: RE: Hyperlink
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi Enak,

When you first browse a page, you ask for a fresh copy. This is called a
GET request. When ASP.NET processes a GET request, IsPostBack is false.
Later, you can submit the page with a button or link button (not a
hyperlink) to submit the form back to itself along with any data on the
page. This is called a POST request. When ASP.NET
processes a POST
request,
IsPostBack is true.

With a hyperlink, the page request is type GET. That
means it's asking
for
a fresh copy of the page and IsPostBack is false. If you want to set the
properties of the hyperlink during the post back, then you need to send a
request of type POST, such as with a button or link button.

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the
three
straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties,
and confers no
rights.
.
 
E

enak

I figured it out. It was a circular reference. Thanks for
your help.
-----Original Message-----
mike thanks for your reply. The first page is called
CaseView.aspx. On that page is the hyperlink that points
to the page CAseViewEdit.aspx

IsPostBack comes back as FALSE. I don't know if this is
correct but I would think that it is because I should not
be posting to the first page.

All of the other links on the page work fine but then I am
using javascript to create a popup with those links.

Any ideas? I will try to redo the link, again.

Thanks
enak
-----Original Message-----
Hi Enak,

Pardon me, I misread your question. You did use NOT IsPostBack which is
correct.

When you submit a page with a button, it submits back to itself. Does your
hyperlink point back to itself?

I tried to reproduce your problem as follows:

* New page named Hyper1
* I put a hyperlink on it
* I added this to the code-behind load event
If Not IsPostBack Then
HyperLink1.NavigateUrl = "grid1.aspx? value=test"
End If

The result was that the hyperlink navigated to my other page named grid1
and it included the query string information.

What is the name of the page you are using for this hyperlink? Is it
CaseViewEdit.aspx? Or, is CaseViewEdit.aspx a separate page?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers
that
they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties,
and
confers no rights.
--------------------
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
From: (e-mail address removed) ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 09 Oct 2003 00:05:30 GMT
Subject: RE: Hyperlink
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi Enak,

When you first browse a page, you ask for a fresh
copy.
This is called a with
any data on the
processes a POST
request, means it's asking
for three and confers no
rights.
the
runat="server"
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top