Here's some code that I'm using to create a simple list of logical drive
letters (my web application impersonates a user). I'm finding that my event
handler doesn't fire. Can anyone give me a hint as to why it doesn't work?
It's nearly a copy of some sample code that I lifted from a friend, whose
code works (so he says!). By the way, I'm using a dotnet Table control in
the ASPX page which starts off empty, it's ID is dirTable.
By the way, I have a co-worker who had the same issue a year ago, and he
ended up associating client side JavaScript which set a hidden field, and
then called submit().
----------------------
private void Page_Load(objec t sender, System.EventArg s e)
{
if ( !IsPostBack )
{
SetupDriveList( );
}
}
void SetupDriveList( )
{
string[] drives = Directory.GetLo gicalDrives();
for (int i = 0; i < drives.Length; i++)
{
if ( drives[i][0] == 'A' || drives[i][0] == 'B' )
{
continue;
}
TableRow tr = new TableRow();
// create link button for drive letter
LinkButton lb = new LinkButton();
lb.Text = drives[i];
lb.CommandName = "drive";
lb.CommandArgum ent = drives[i][0].ToString();
lb.Command += new CommandEventHan dler( OnClickLink );
lb.Attributes.A dd("onclick", "OnClickLin k" );
// add link button to table cell
TableCell td = new TableCell();
td.Controls.Add ( lb );
// add table cell to table row
tr.Cells.Add( td );
// add table row to table
dirTable.Rows.A dd( tr );
}
}
void OnClickLink(obj ect O, CommandEventArg s e)
{
string commandName = e.CommandName.T oString();
string commandArg = e.CommandArgume nt.ToString();
} 5 1819
Steve,
This is just a guess, but I don't think you need to append the onClick
attribute to a link button web control unless you are trying to run client
side code. ASP .NET renders the control as an anchor <a> element that is set
to post back to the sever with the controls arguments. View the source of
the control should be something similar to:
<a href="javascrip t:__doPostBack( '_ctl0','')">My Link Button</a>
Try to remove/remark out the following line and see if your handler fires.
lb.Attributes.A dd("onclick", "OnClickLin k" );
Jared
"Steve Harclerode" <st*****@bit.ce ntral.com> wrote in message
news:Og******** ******@tk2msftn gp13.phx.gbl... Here's some code that I'm using to create a simple list of logical drive letters (my web application impersonates a user). I'm finding that my event handler doesn't fire. Can anyone give me a hint as to why it doesn't work? It's nearly a copy of some sample code that I lifted from a friend, whose code works (so he says!). By the way, I'm using a dotnet Table control in the ASPX page which starts off empty, it's ID is dirTable.
By the way, I have a co-worker who had the same issue a year ago, and he ended up associating client side JavaScript which set a hidden field, and then called submit().
----------------------
private void Page_Load(objec t sender, System.EventArg s e) { if ( !IsPostBack ) { SetupDriveList( ); } }
void SetupDriveList( ) { string[] drives = Directory.GetLo gicalDrives(); for (int i = 0; i < drives.Length; i++) { if ( drives[i][0] == 'A' || drives[i][0] == 'B' ) { continue; } TableRow tr = new TableRow();
// create link button for drive letter LinkButton lb = new LinkButton(); lb.Text = drives[i]; lb.CommandName = "drive"; lb.CommandArgum ent = drives[i][0].ToString(); lb.Command += new CommandEventHan dler( OnClickLink ); lb.Attributes.A dd("onclick", "OnClickLin k" );
// add link button to table cell TableCell td = new TableCell(); td.Controls.Add ( lb );
// add table cell to table row tr.Cells.Add( td );
// add table row to table dirTable.Rows.A dd( tr ); } }
void OnClickLink(obj ect O, CommandEventArg s e) { string commandName = e.CommandName.T oString(); string commandArg = e.CommandArgume nt.ToString(); }
Steve,
The order of events is Page Load --> Process Events (e.g. button click) -->
Page Render. Because you create your buttons dynamically, and *only* when
it's not a postback, the buttons aren't there the next time around to get the
event. You need to either rebuild them each time, or store them in viewstate,
or instead of rolling the table yourself use a repeater/datalist/datagrid in
which case the viewstate save/fetch will be handled for you.
hth,
Bill
"Steve Harclerode" wrote: Here's some code that I'm using to create a simple list of logical drive letters (my web application impersonates a user). I'm finding that my event handler doesn't fire. Can anyone give me a hint as to why it doesn't work? It's nearly a copy of some sample code that I lifted from a friend, whose code works (so he says!). By the way, I'm using a dotnet Table control in the ASPX page which starts off empty, it's ID is dirTable.
By the way, I have a co-worker who had the same issue a year ago, and he ended up associating client side JavaScript which set a hidden field, and then called submit().
----------------------
private void Page_Load(objec t sender, System.EventArg s e) { if ( !IsPostBack ) { SetupDriveList( ); } }
void SetupDriveList( ) { string[] drives = Directory.GetLo gicalDrives(); for (int i = 0; i < drives.Length; i++) { if ( drives[i][0] == 'A' || drives[i][0] == 'B' ) { continue; } TableRow tr = new TableRow();
// create link button for drive letter LinkButton lb = new LinkButton(); lb.Text = drives[i]; lb.CommandName = "drive"; lb.CommandArgum ent = drives[i][0].ToString(); lb.Command += new CommandEventHan dler( OnClickLink ); lb.Attributes.A dd("onclick", "OnClickLin k" );
// add link button to table cell TableCell td = new TableCell(); td.Controls.Add ( lb );
// add table cell to table row tr.Cells.Add( td );
// add table row to table dirTable.Rows.A dd( tr ); } }
void OnClickLink(obj ect O, CommandEventArg s e) { string commandName = e.CommandName.T oString(); string commandArg = e.CommandArgume nt.ToString(); }
I have what appears to be the same problem.
I realized that I needed to recreate the screen add re-add the controls
before the events for the controls would fire. However, they only fire every
other submit!
"Bill Borg" <Bi******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com... Steve,
The order of events is Page Load --> Process Events (e.g. button
click) --> Page Render. Because you create your buttons dynamically, and *only* when it's not a postback, the buttons aren't there the next time around to get
the event. You need to either rebuild them each time, or store them in
viewstate, or instead of rolling the table yourself use a repeater/datalist/datagrid
in which case the viewstate save/fetch will be handled for you.
hth,
Bill
"Steve Harclerode" wrote:
Here's some code that I'm using to create a simple list of logical drive letters (my web application impersonates a user). I'm finding that my
event handler doesn't fire. Can anyone give me a hint as to why it doesn't
work? It's nearly a copy of some sample code that I lifted from a friend,
whose code works (so he says!). By the way, I'm using a dotnet Table control
in the ASPX page which starts off empty, it's ID is dirTable.
By the way, I have a co-worker who had the same issue a year ago, and he ended up associating client side JavaScript which set a hidden field,
and then called submit().
----------------------
private void Page_Load(objec t sender, System.EventArg s e) { if ( !IsPostBack ) { SetupDriveList( ); } }
void SetupDriveList( ) { string[] drives = Directory.GetLo gicalDrives(); for (int i = 0; i < drives.Length; i++) { if ( drives[i][0] == 'A' || drives[i][0] == 'B' ) { continue; } TableRow tr = new TableRow();
// create link button for drive letter LinkButton lb = new LinkButton(); lb.Text = drives[i]; lb.CommandName = "drive"; lb.CommandArgum ent = drives[i][0].ToString(); lb.Command += new CommandEventHan dler( OnClickLink ); lb.Attributes.A dd("onclick", "OnClickLin k" );
// add link button to table cell TableCell td = new TableCell(); td.Controls.Add ( lb );
// add table cell to table row tr.Cells.Add( td );
// add table row to table dirTable.Rows.A dd( tr ); } }
void OnClickLink(obj ect O, CommandEventArg s e) { string commandName = e.CommandName.T oString(); string commandArg = e.CommandArgume nt.ToString(); }
Nope, that didn't do it. That's how it was before, I just forgot to remove
that code from my post. Oops.
Thanks for the reply.
- Steve
"Jared" <as***********@ nospam.com> wrote in message
news:10******** *****@corp.supe rnews.com... Steve, This is just a guess, but I don't think you need to append the onClick attribute to a link button web control unless you are trying to run client side code. ASP .NET renders the control as an anchor <a> element that is
set to post back to the sever with the controls arguments. View the source of the control should be something similar to:
<a href="javascrip t:__doPostBack( '_ctl0','')">My Link Button</a>
Try to remove/remark out the following line and see if your handler
fires. lb.Attributes.A dd("onclick", "OnClickLin k" );
Jared
"Steve Harclerode" <st*****@bit.ce ntral.com> wrote in message
Thanks, I didn't realize you could store that kind of object in the
Viewstate.
- Steve
"Bill Borg" <Bi******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com... Steve,
The order of events is Page Load --> Process Events (e.g. button
click) --> Page Render. Because you create your buttons dynamically, and *only* when it's not a postback, the buttons aren't there the next time around to get
the event. You need to either rebuild them each time, or store them in
viewstate, or instead of rolling the table yourself use a repeater/datalist/datagrid
in which case the viewstate save/fetch will be handled for you.
hth,
Bill
"Steve Harclerode" wrote: This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fresh Air Rider |
last post by:
Hello
Could anyone please explain how I can pass more than one
arguement/parameter value to a function using <asp:linkbutton> or is
this a major shortfall of the language ?
Consider the following code fragments in which I want to list through
all files on a directory with a link to download each file by passing
a filename and whether or not to force the download dialog box to
appear.
|
by: Stan |
last post by:
This is very weird - linkbutton submits the form, but the
event handler is not being called:
<asp:linkbutton Runat=server CssClass=NormalA
OnClick=btnTest_Click>Test</asp:linkbutton>
protected void btnTest_Click(object sender,
System.EventArgs e)
{
Response.Write ("Test");
|
by: Al Cohen |
last post by:
I'm using a LinkButton to call some code, then do a redirect. The code
does some queries, sends some emails, and takes a few moments before the
redirect is performed.
I'd like to disable my LinkButton during this period to prevent multiple
submissions. (Obviously) the disabling should be done at the client
side to prevent any delay. I've tried adding some javascript to
LinkButton.Attributes:
LinkButton1.Attributes.Add("onclick",...
|
by: George Durzi |
last post by:
I currently have an href inside of an asp:repeater
<a href='<%# String.Concat("PDFReader.aspx?id=",
DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>'
target="_blank">View</a>
Clicking View will open a new browser and load PDFReader.aspx
My client would like me to hide the address bar and toolbar on this new
|
by: Shivakumar |
last post by:
Hi all,
Recently i have updated my vs.net 2003 project to vs.net 2005 and i
have successfully converted my code and found no problem with all my
controls except the one which is the linkbutton.
I have added the linkbutton control in my datagrid and it rendered perfectly
but whenever i clicked the linkbutton am getting this error
'event' is null or not an object.
| |
by: Alex Maghen |
last post by:
I have a DataGrid control with a LinkButton command column that deletes the
row. What I want to do is set it up so that there's a client-side Confirm
alert BEFORE the actual Delete command gets called on the server-side. That's
easy to do with normal buttons, etc. as follows...
<asp:Button ID="ConfirmBtn" Text="ConfimMe!"
OnClientClick="if(!confirm('Are you sure?'))return false;"
OnClick="ConfirmBtnClickHandler" Runat="server" />
But...
|
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= |
last post by:
I have two sets of search criteria on my page.
They are placed inside two DIV tags made visible/hidden by a client script.
In each DIV tag I have a LinkButton that performs the search from each set.
By using AJAX I get the resulting list expand and collapse without page
reload.
All work smoothly.
But one user today complained that the submit behaviour doesn't work like
before.
|
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= |
last post by:
Hi,
I have a strange issue occurring with LinkButtons that are dynamically added
to each (data) row of my DataGrid on that grid's ItemDataBound event. Each
LinkButton is assigned its own event handler to deal with the Command event,
but for some reason I can get this to work in a C# project but not in a newly
created VB.NET one.
The relevant VB.NET is as follows:
|
by: Jeff |
last post by:
Hi, I have a ASP.NET 2.0 Web Application. Many of the pages use the ASP.NET
GridView with paging and sorting.
One of the columns of this Gridview is a template column (LinkButton). The
data being retrieved and showed in this GridView produce more than one page
of data.
A given user clicks on the first row hyper link on the Grid on the first
page, then the first row hyper link color changes to look as "visited".
Then the user navigates to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |