473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Progromaticly build OnClientClick

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.
Jul 22 '08 #1
1 2414
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?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark Handy" <mj*****@gmail.comwrote in message
news:94**********************************@d77g2000 hsb.googlegroups.com...
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.

Jul 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Buddy Ackerman | last post by:
I want to disable a form button after it's pressed so that the user can't click it twice. So, I set the onClientClick property to "this.disabled=true;return true;". This has the effect of...
0
by: Peter S. | last post by:
As far as from what I read, onclientclick executes first when enabling that event on a WebControl button. Is there any way I can run some code first by detecting that event fired? Or is there some...
0
by: jtencate | last post by:
I am trying to add an OnClientClick event to links in an asp:Menu. I tried using a StaticItemTemplate to bind the MenuItem data to a LinkButton with an OnClientClick attribute. This works fine to...
5
by: Dan | last post by:
Hi, i try to redirect to another aspx page with jscript. I use "OnClientClick" but nothing happens. I tried two ways. What am i doing wrong? Thanks Dan ....
3
by: Phil | last post by:
Hi, I'm a little confused about the precedence of actions between OnClientClick and OnClick. In this example, what will be executed first and why? Thanks Phil in code-behind:...
0
by: sloan | last post by:
Asp.Net 2.0 Inside a repeater, I'm trying to do a linkbutton with a OnClientClick <asp:LinkButton ID="lnbSelect" runat="server"...
7
by: =?Utf-8?B?RWFnbGVSZWRASGlnaEZseWluZ0JpcmRzLmNvbQ== | last post by:
I am having trouble getting client-side events to fire on ImageButtons. Instead I am seeing postbacks. The client-side handlers end with "return false;" but they are never called. ...
2
by: dddan | last post by:
Here's my code: <asp:LinkButton OnClick="DeleteFile" OnClientClick="if (!confirm ('Are you certain you want to delete this file?') ) return false;" runat="server" ID="DeleteButton">DELETE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.