Capture hyperlink text property

G

Guest

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

is this a standard HREF or does it have a postback? If it's a standard HREF
you will have to pass the call to some clientside code, passing in the text,
and then processing it and redirecting. If it's a postback you can get the
info more easily but more importantly you can do what you want/need with it
then (session value, querystring, etc).
 
G

Guest

Standard HREF; there is no postback. page_1 and page_2 are two different
pages.

Each href looks something like: href="page_2.aspx?q1=value1&q2=value2" where
value1 and value2 change from link to link.

Also, I do not have the option to pass the text property in the querystring.

page_2 merely needs the value of the hyperlink's text. I can handle the
processing once I've got it. I just don't know how to get it.

So, any ideas?

For example, how would you "pass the call to some clientside code, passing
in the text?"

Thanks,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
 
G

Guest

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang
 
G

Guest

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

Joe said:
I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

without postback and without querystring you are limited. I would say try the
javascript call.
add an onClick to the HREF to a javascript function, passing in the text and
URL.
Have the javascript function save this to a session item, then redirect to
the URL.

Plenty of samples of this out there...

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
G

Guest

I have been looking at samples for over an hour and haven't found one that
shows how to retrieve the text. Do you know how? The URL is easy; the text
is a mystery....
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
 
G

Guest

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

Joe said:
Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

Joe said:
I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Curt,

I did not misunderstand. I can't PASS the text if I can't RETRIEVE the text.

I have tried the following javascript:

function parseHyperlinkId(o) {
alert("Thomas Jefferson was a hack!");
alert(o.text);
alert(o.href);
alert(o.target);
}

Using the following Server side code to link the hyperlink's onClick event
to the javascript:

hLink.Attributes.Add("onClick", "return parseHyperlinkId(this);")

The works fine except that o.text returns "undefined." Do you know why? Do
you know how to retrieve the text from the link? Which property I should
use? Do you know what's wrong with my code?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
 
G

Guest

Thank you, thank you, thank you, thank you.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

Joe said:
Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

Joe said:
Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

Joe said:
Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

Joe said:
Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Elton,

Do you know if disabling the page's viewstate diaables the viewstates of the
controls on teh page?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

Joe said:
Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

Joe said:
Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Set breakpoints in your code and trace running step by step to see what
happens. It might help.

Joe said:
EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

Joe said:
Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Hi Elton,

The company that I work for requires that page-level ViewState be turned
off. So, just to try it, I turned page-level Viewstate on and the code
works. I have the impression that if the page-level ViewState is turned off,
the individual control's viewstates will not work, regardless of whether or
not they are turned on. Do you know anything about this?

I will see if I can find another solution. I have thought of using
AddHandler to link Sub declarations to the LinkButton's Click event. This
has worked with some success in the past and might provide a solution now.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Set breakpoints in your code and trace running step by step to see what
happens. It might help.

Joe said:
EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

:

Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

You can try another way. When postback, in Page_Load event, re-bind the
datagrid’s data source. The disadvantage is that if you need collect user
changed data from the datagrid, the re-binding will overwriting user changed
data.

HTH

Elton


Joe said:
Hi Elton,

The company that I work for requires that page-level ViewState be turned
off. So, just to try it, I turned page-level Viewstate on and the code
works. I have the impression that if the page-level ViewState is turned off,
the individual control's viewstates will not work, regardless of whether or
not they are turned on. Do you know anything about this?

I will see if I can find another solution. I have thought of using
AddHandler to link Sub declarations to the LinkButton's Click event. This
has worked with some success in the past and might provide a solution now.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Set breakpoints in your code and trace running step by step to see what
happens. It might help.

Joe said:
EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

:

Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Elton,

The user can't change any data in the datagrid. We use it solely for
display purposes.

I'm going to post this in today's posts (I am switching back and forth
between too many windows and need to consolidate.). Please feel free to
continue our discussion. I appreciate your suggestions.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
You can try another way. When postback, in Page_Load event, re-bind the
datagrid’s data source. The disadvantage is that if you need collect user
changed data from the datagrid, the re-binding will overwriting user changed
data.

HTH

Elton


Joe said:
Hi Elton,

The company that I work for requires that page-level ViewState be turned
off. So, just to try it, I turned page-level Viewstate on and the code
works. I have the impression that if the page-level ViewState is turned off,
the individual control's viewstates will not work, regardless of whether or
not they are turned on. Do you know anything about this?

I will see if I can find another solution. I have thought of using
AddHandler to link Sub declarations to the LinkButton's Click event. This
has worked with some success in the past and might provide a solution now.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
Set breakpoints in your code and trace running step by step to see what
happens. It might help.

:

EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

:

Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 
G

Guest

Actually, I think once you re-bind datagrid’s data source in postback,
datagrid’s events will work event disabled datagrid viewstate. Anyhow, you
can try.

HTH

Elton

Joe said:
Elton,

The user can't change any data in the datagrid. We use it solely for
display purposes.

I'm going to post this in today's posts (I am switching back and forth
between too many windows and need to consolidate.). Please feel free to
continue our discussion. I appreciate your suggestions.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Elton W said:
You can try another way. When postback, in Page_Load event, re-bind the
datagrid’s data source. The disadvantage is that if you need collect user
changed data from the datagrid, the re-binding will overwriting user changed
data.

HTH

Elton


Joe said:
Hi Elton,

The company that I work for requires that page-level ViewState be turned
off. So, just to try it, I turned page-level Viewstate on and the code
works. I have the impression that if the page-level ViewState is turned off,
the individual control's viewstates will not work, regardless of whether or
not they are turned on. Do you know anything about this?

I will see if I can find another solution. I have thought of using
AddHandler to link Sub declarations to the LinkButton's Click event. This
has worked with some success in the past and might provide a solution now.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Set breakpoints in your code and trace running step by step to see what
happens. It might help.

:

EnableViewState is on. Any other ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Check the datagrid's EnableViewState, if it's false, enable it. Disabled
EnableViewState causes datagrid not function properly.

HTH

Elton

:

Elton,

The ItemCommand is not firing. Here is my code:

Private Sub dgForms_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgForms.ItemCommand

hdnFormNumber.Value = CType(e.Item.Cells(0).Controls(0), LinkButton).Text
End Sub

I've had this problem before with the SortCommand, but don't quite know how
to resolve it. Do you have any ideas why this wouldn't fire?

Joe
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

No you can't cast Hyperlink to link button. You should change HyperLinkColumn
to ButtonColumn (ButtonType=LinkButton). Then you can do your logic in
datagrid_ItemCommand event on server-side.

HTH

Elton

:

Thanks Elton. I can't use the QueryString due to Business Requirements. How
do I cast the Hyperlink column in the datagrid to a link button?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


:

Hi Joe,

Two solutions:
1. Still use Hyperlink column in the datagrid, but add something in
datagrid_itemDatabound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[link_column_index].Controls[0];
link.NavigateUrl += "&text=" + link.Text;
}

Then in page2, you can retrieve it from querystring.

2. Change Hyperlink column to LinkButton. Then you can process in
datagrid_ItemCommand event: pass data to Session, Cookie, or queryString and
redirect to page2.


HTH

Elton Wang

:

I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.

I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the Page_Load event of page_2. What I
don't know is how to populate the hdnClickedLinkText field on page_1 when the
hyperlink is clicked. I've thought about using AddHandler but there is no
exposed click event for the hyperlink control. I could design a custom class
which inherits from the hyperlink class and implement my own Click event, but
this seems a bit much when a simpler solution may exist.

Does anyone have any other ideas?

TIA,
 

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

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top