473,386 Members | 1,621 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.

How to call a javascript function from a HTML button on a user control

J-T
I have a user control called "Test1" with two button on it ,one is input and
the other one is a server control as follow:

<input type="button"
onClick="this.disabled=true;document.getElementByI d(btnSend).click();value="Go!">
<asp:button id="btnSend" runat="server" onClick="click" Width="90px"
Text="HiddenControl" Visible="False"></asp:button>

As you can see the asp.net button is calling a java script function as
follows:

<script language="c#" runat="server">
void click(object sender, EventArgs e)
{
//do something
}
</script>

when I run this code I get a java script error that "btnSend" is undefined
which generated from the first line (HTML button).I don;t know how to call
click even of server control from the html control.Dose anyone know how to
tackle this problem?

Thanks a lot


Nov 19 '05 #1
7 2518
"J-T" <Re**@Reza.Com> wrote in
news:eG**************@TK2MSFTNGP09.phx.gbl:
when I run this code I get a java script error that "btnSend" is
undefined which generated from the first line (HTML button).I don;t
know how to call click even of server control from the html
control.Dose anyone know how to tackle this problem?


You need to retrieve the rendered button name by using the property
btnSend.clientID.
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2
J-T
You mean I should replace btnSend with btnSend.clientID in
document.getElementById(btnSend).click();?

Thanks
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"J-T" <Re**@Reza.Com> wrote in
news:eG**************@TK2MSFTNGP09.phx.gbl:
when I run this code I get a java script error that "btnSend" is
undefined which generated from the first line (HTML button).I don;t
know how to call click even of server control from the html
control.Dose anyone know how to tackle this problem?


You need to retrieve the rendered button name by using the property
btnSend.clientID.
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #3
"J-T" <Re**@Reza.Com> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
As you can see the asp.net button is calling a java script function as
follows:

<script language="c#" runat="server">


Er, no it isn't - it's calling an in-line C# function...

And that's where the problem lies. Why are you trying to write your
server-side code in-line?

It looks to me as if you're trying to prevent users double-clicking your
first button by mistake, by disabling it on the first click - that's fine.

So, do the following, and all will be well:

1) Recreate the page with a separate code-behind page

2) Add the following client-side code to the BODY section:

<form id=frm runat=server>

<asp:button id="btnSend" runat="server" onClick="btnSend_Click()"
Width="90px" Text="Go!" />

</form>

3) In the code-behind page, add the following line *above* the Page_Load
event:

protected Button btnSend;

4) In the code-behind page, add the following line *inside* the Page_Load
event:

btnSend.Attributes.Add("onclick", "this.disabled=true;");

5) In the code-behind page, add the following code *underneath* the
Page_Load event:

public void btnSend_Click(object sender, System.EventArgs e)
{
//do something
}
Nov 19 '05 #4
"J-T" <Re**@Reza.Com> wrote in news:eZ**************@TK2MSFTNGP12.phx.gbl:
You mean I should replace btnSend with btnSend.clientID in
document.getElementById(btnSend).click();?


Yup exactly. But the ClientID property is a codebehind property.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #5
J-T
> 1) Recreate the page with a separate code-behind page

2) Add the following client-side code to the BODY section:

<form id=frm runat=server>

<asp:button id="btnSend" runat="server" onClick="btnSend_Click()"
Width="90px" Text="Go!" />

</form>

I am trying to do this in a user control ,I cannot have a form.

Thanks

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl... "J-T" <Re**@Reza.Com> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
As you can see the asp.net button is calling a java script function as
follows:

<script language="c#" runat="server">


Er, no it isn't - it's calling an in-line C# function...

And that's where the problem lies. Why are you trying to write your
server-side code in-line?

It looks to me as if you're trying to prevent users double-clicking your
first button by mistake, by disabling it on the first click - that's fine.

So, do the following, and all will be well:

1) Recreate the page with a separate code-behind page

2) Add the following client-side code to the BODY section:

<form id=frm runat=server>

<asp:button id="btnSend" runat="server" onClick="btnSend_Click()"
Width="90px" Text="Go!" />

</form>

3) In the code-behind page, add the following line *above* the Page_Load
event:

protected Button btnSend;

4) In the code-behind page, add the following line *inside* the Page_Load
event:

btnSend.Attributes.Add("onclick", "this.disabled=true;");

5) In the code-behind page, add the following code *underneath* the
Page_Load event:

public void btnSend_Click(object sender, System.EventArgs e)
{
//do something
}

Nov 19 '05 #6
"J-T" <Re**@Reza.Com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I am trying to do this in a user control ,I cannot have a form.


Well, like most people, I'm not psychic - you never mentioned a user control
till now...

So, remove the form tags...
Nov 19 '05 #7
J-T
I tried what you said ,it dosen't work :-(

Thanks anyway

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
"J-T" <Re**@Reza.Com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I am trying to do this in a user control ,I cannot have a form.


Well, like most people, I'm not psychic - you never mentioned a user
control till now...

So, remove the form tags...

Nov 19 '05 #8

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

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
11
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
4
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.