onClick Event Not Firing

G

Guest

I posted this question in the C# discussion group but am posting it here
also since ASP is involved.

I'm new to C# and need some help regarding an onClick event not firing.

I have a data grid that I add a cell to programatically. The cell is a
hyperlink and the onClick is set to _doPostBack. In my code I handle the
event but when I click on that added hyperlink nothing happens.

Here's my code (I'll just show the relevant stuff).
The data grid is dgBillSummary.

In MyClass.ascx I have a hidden LinkButton:
<asp:LinkButton id="lnkPostBack" runat="server" Height="1px"
Visible="False">PostBack</asp:LinkButton>

Here's MyClass.ascx.cs
public class MyClass
protected System.Web.UI.WebControls.LinkButton lnkPostBack;
|
private void InitializeComponent()
this.lnkPostBack.Click += new System.EventHandler(this.lnkPostBack_Click);
|
private void dgBillSummary_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
|
Label lblShowAll = new Label();
lblShowAll.Text = "<a name=\"#ShowAll\" class=\"HypLink\"
onContextMenu=\"NoContextmenu();\" href=\"#ShowAll\"
onClick=\"_doPostBack('lnkPostBack','ShowAll');\"> Show All</a>";

e.Item.Cells[0].Controls.Add(lblShowAll); // here I'm adding a cell to the
data grid

|

// Here's the onClick event code that I never get to
private void lnkPostBack_Click(object sender, System.EventArgs e)
{
|
}

Any suggestions will be greatly appreciated!

TIA,
Rita
 
B

bruce barker

because the link button is not visible, it not rendered. thus it knows
it will not receive any events, so none are fired. you need to make it
visible, and set the style="display:none".


a better approach would be to create your own callback handler, and not
use a fake link.

-- bruce (sqlwork.com)
 
G

Guest

Thanks Bruce. I tried that but the onClick event still did not happen.
Since I just needed the __doPostBack __EVENTARGUMENT value and was able to
retrieve it in the OnInit I resolved my issue.

Rita

bruce barker said:
because the link button is not visible, it not rendered. thus it knows
it will not receive any events, so none are fired. you need to make it
visible, and set the style="display:none".


a better approach would be to create your own callback handler, and not
use a fake link.

-- bruce (sqlwork.com)

I posted this question in the C# discussion group but am posting it here
also since ASP is involved.

I'm new to C# and need some help regarding an onClick event not firing.

I have a data grid that I add a cell to programatically. The cell is a
hyperlink and the onClick is set to _doPostBack. In my code I handle the
event but when I click on that added hyperlink nothing happens.

Here's my code (I'll just show the relevant stuff).
The data grid is dgBillSummary.

In MyClass.ascx I have a hidden LinkButton:
<asp:LinkButton id="lnkPostBack" runat="server" Height="1px"
Visible="False">PostBack</asp:LinkButton>

Here's MyClass.ascx.cs
public class MyClass
protected System.Web.UI.WebControls.LinkButton lnkPostBack;
|
private void InitializeComponent()
this.lnkPostBack.Click += new System.EventHandler(this.lnkPostBack_Click);
|
private void dgBillSummary_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
|
Label lblShowAll = new Label();
lblShowAll.Text = "<a name=\"#ShowAll\" class=\"HypLink\"
onContextMenu=\"NoContextmenu();\" href=\"#ShowAll\"
onClick=\"_doPostBack('lnkPostBack','ShowAll');\"> Show All</a>";

e.Item.Cells[0].Controls.Add(lblShowAll); // here I'm adding a cell to the
data grid

|

// Here's the onClick event code that I never get to
private void lnkPostBack_Click(object sender, System.EventArgs e)
{
|
}

Any suggestions will be greatly appreciated!

TIA,
Rita
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top