472,371 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 2456
"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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.