473,563 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.d isabled=true;do cument.getEleme ntById(btnSend) .click();value= "Go!">
<asp:button id="btnSend" runat="server" onClick="click" Width="90px"
Text="HiddenCon trol" 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 2535
"J-T" <Re**@Reza.Co m> wrote in
news:eG******** ******@TK2MSFTN GP09.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.clientI D.
--
Lucas Tam (RE********@rog ers.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.clientI D in
document.getEle mentById(btnSen d).click();?

Thanks
"Lucas Tam" <RE********@rog ers.com> wrote in message
news:Xn******** *************** ****@127.0.0.1. ..
"J-T" <Re**@Reza.Co m> wrote in
news:eG******** ******@TK2MSFTN GP09.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.clientI D.
--
Lucas Tam (RE********@rog ers.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.Co m> wrote in message
news:eG******** ******@TK2MSFTN GP09.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="btnSen d_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.Attribu tes.Add("onclic k", "this.disabled= true;");

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

public void btnSend_Click(o bject sender, System.EventArg s e)
{
//do something
}
Nov 19 '05 #4
"J-T" <Re**@Reza.Co m> wrote in news:eZ******** ******@TK2MSFTN GP12.phx.gbl:
You mean I should replace btnSend with btnSend.clientI D in
document.getEle mentById(btnSen d).click();?


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

--
Lucas Tam (RE********@rog ers.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="btnSen d_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******** ******@TK2MSFTN GP10.phx.gbl... "J-T" <Re**@Reza.Co m> wrote in message
news:eG******** ******@TK2MSFTN GP09.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="btnSen d_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.Attribu tes.Add("onclic k", "this.disabled= true;");

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

public void btnSend_Click(o bject sender, System.EventArg s e)
{
//do something
}

Nov 19 '05 #6
"J-T" <Re**@Reza.Co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP10.phx.gbl...
"J-T" <Re**@Reza.Co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.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
5052
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 they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT...
3
4023
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: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the...
14
5437
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 that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I...
4
4274
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 I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to...
11
4971
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, making it visible or not. Yep you guessed it, expanding tree type functionality. The header has an onclick event onclick='Doexpandcollapse
4
4210
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 the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and...
3
3660
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 html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
4
3846
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 am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
4
4233
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 control.. but if i add javascript in page in which i am adding user control then that javascript is executed properly. i tested by displaying alert...
0
7659
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6244
agi2029
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...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.