472,103 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 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 51998
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Mark Lingen | last post: by
1 post views Thread by Andy Rose | last post: by
4 posts views Thread by Winista | last post: by

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.