473,394 Members | 1,722 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,394 software developers and data experts.

How do I fire a server side button click event from javascript?

Hi,

I need to fire a server side button click event from my client side
javascript. The client side javascript code follows:

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");
form1.<%= hiddenTextField.ClientID %>.value = strname;
form1.<% =btnSubmit.ClientID %>.click();

}
</script>

You can see that I'm trying to use the "click();" event for the <asp:
"btnSubmit" button but it dosen't seem to work.
Any ideas?!

Thanks in advance for your help.

Steve

May 27 '06 #1
3 52194
the ModalPopup under ATlas Toolkit will do that for you ...

http://atlas.asp.net/atlastoolkit/Mo...odalPopup.aspx
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Steve Kershaw" <st***********@yahoo.com> escreveu na mensagem
news:11*********************@g10g2000cwb.googlegro ups.com...
Hi,

I need to fire a server side button click event from my client side
javascript. The client side javascript code follows:

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");
form1.<%= hiddenTextField.ClientID %>.value = strname;
form1.<% =btnSubmit.ClientID %>.click();

}
</script>

You can see that I'm trying to use the "click();" event for the <asp:
"btnSubmit" button but it dosen't seem to work.
Any ideas?!

Thanks in advance for your help.

Steve

May 27 '06 #2
I'm sorry, maybe I didn't explain myself properly. I don't need a popup
that allows the user to enter some text (their name in this case). The
javascript I displayed already does that:

strname = prompt("What is your name", "");

What I need is, after the user enters their name and clicks the OK
button on the javascript (client side) prompt popup, I need the
javascript function to call a ( server side, ASP.NET, C# ) OnClick
event.... Like this:

form1.<% =btnSubmit.ClientID %>.click();

The server side event looks like:

protected void btnSubmit_Click(object sender, EventArgs e)
{
TextBox2.Text = hiddenTextField.Value;
Response.Write("Your name is: " + hiddenTextField.Value);
}

However, it dosen't work!
Can anyone help?!!

Steve

May 27 '06 #3
Hai Steve,

I hope u r button id is "btnSubmit"

Step 1:
In the server side page load event just add this code...

Page.GetPostBackEventReference(ImageButton1)

Step 2:-

Try calling this line " __doPostBack('btnSubmit','OnClick');"

call the above function "callPostBack" after u r prompt
statement.

eg:-

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");

// if its a valid name then just call post back..
__doPostBack('btnSubmit','OnClick');

}
</script>

The java script will trigger a postback as if it was initiated by
the Button.. u can handle it on u r server side

hope this helps u

Regards
Vinu

May 27 '06 #4

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

Similar topics

3
by: ~J~ | last post by:
Hi everyone I'm positive this is possible, just never needed it until now and I don't have a clue where to start I have an XML document that is attached to an XSL style sheet, within this XSL...
4
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
1
by: Andy Rose | last post by:
..Hi all, I want to catch an 'enter' keypress event on a web form and submit the form as if a button had been clicked rather than the default post back behaviour. I know the following javascript...
6
by: shil | last post by:
I have a server side button that needs to do some preperation and afterwards, if everything goes well, open a new browser with a specific url. I know how to execute javascript from a server side...
4
by: Winista | last post by:
I have a page with bunch of user controls and standard controls on the page. And then I have a Button control on the page which is used to save the data on server side. All was working fine and...
17
by: Eric | last post by:
I'm new to JavaScript and I wrote this code to play with. Oddly, if I enter text in a box and then press the button, I only get the onChange event for the text box and not the button's onclick...
1
by: babashankar | last post by:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var change = false; function showmsg(id) { var res =...
19
Frinavale
by: Frinavale | last post by:
I'm in the middle of implementing a custom Ajax enabled Server Control. At this point I need help finding the answer to an Ajax Framework question...here it goes: I have a Server Control that...
4
yarbrough40
by: yarbrough40 | last post by:
can any one tell me if there is a way to pass a string variable to a button click event? ultimately I am looking to fire client side Javascript "__doPostBack('Button1','click','')" and have the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.