button click event problem

O

ODAN

I have an ASP.NET application written in C#. one of the web form where you
create user information and user name has a button to click to print
selected user information for the users record. However when this button is
clicked it does nothing the first time, bring up the popup the second time
it is clicked. We need this button to bring up the popup with the
information the first time it is clicked. Any ideas will be greatly
appreciated. The code in the btn_click event is listed below.


private void btnPrint_Click(object sender, System.EventArgs e)

{

string securityQuestion=ddlQuestion.SelectedItem.Text;

securityQuestion=securityQuestion.Replace("'","\\'");

lblName.Text=txtUserName.Text;

lblPswd.Text=txtPassword.Text;

lblSecQuestion.Text= securityQuestion;

lblAns.Text=txtAnswer.Text;

btnPrint.Attributes.Add("OnClick","return
PrintDocument('"+divusername.ClientID+"');");

}



Thanks!
 
K

Kevin Spencer

Not sure what you mean by "bring up the popup" but it looks like you're
handling a Click event by adding a client-side click event handler. That
would cause the client-side click event handler to fire only after the
button was clicked a second time.

Instead, if the function being called should be run immediately, just add a
JavaScript to the page that calls the function.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Nyuck nyuck nyuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top