Progromaticly build OnClientClick

  • Thread starter Thread starter Mark Handy
  • Start date Start date
M

Mark Handy

Here's my code snippet:

protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterStartupScript("SetFocus",
"<script>document.getElementById('" + txtKeyword.ClientID +
"').focus();</script>");
if (!this.txtKeyword.Text.Trim().Equals(string.Empty))
{
DoSearch();
}
}

private void DoSearch()
{
string section = this.dpdSearchSections.SelectedValue;
string keyword = this.txtKeyword.Text;
this.txtKeyword.Text = string.Empty;
Response.Redirect("AdvancedSearch2.aspx?sec=" + section +
"&search_field_name=" + keyword);

}


So, within DoSearch(), i want to add, an a client side On Click, the
google event tracking code, as an example:
pageTracker._trackPageview('/ClickEvent/homePage/healthSearch/term=');

I want to append 'keyword' after the equals. On the asp:ImageButton i
have OnClientClick="pageTracker._trackPageview('/ClickEvent/homePage/
healthSearch/term=');" which work fine, but i'm stumped on appending
the keyword.

Thanks,
Mark.
 
Mark,

Why not find the control through the Controls property (and the id of
the control) and then modify the OnClientClick property on the ImageButton
control to include your appended text?
 

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

Back
Top