Javascript and vb.net web form (pop up)

C

Christina

Hello !!

I want a link on my vb.net web application, which when clicked, popUp's
up and shows a msg.
AFAIK, Javascript is the best way to go.

So I created an asp:hyperlink, and on its 'on click' event, I have
something like:
Page.RegisterStartupScript("myWinName", showAPopUp(messageString),
where, showAPopUp is a code-behind function which has
window.Open(....). messageString is a string that I am building when
the click event occurs.

I have 2 problems :
1) When the 'on Click' event fires, it posts back the page (I beleive,
its posting it to the server). But I am trying to use client sides
scripting to avoid server posts. Does Page.RegisterStartupScript post
data to the server ? If yes, is there a way I can do this without
posting it to the server ?

2) In the same link mentioned above, this is the sequence i am
following, which creates a problem.
i click the hyperlink, it opens a pop-up, i close it, go to next page.
Now, when I click IE's back button, instead of showing just the
previous page, it shows me the popup first. Is there a way I can avoid
this too ?

Thanks !!
 
C

Cowboy \(Gregory A. Beamer\)

1) You have to circumvent the natural tendency of a hyperlink to link to
something. There are better controls to pop up with.
2) The back button occurs as that was the state of the page before it went
forward. Curing #1 will cure #2.

For my app, I used a linkButton with no href. I then add to the OnClick
event and everything is golden. No refresh of the page.
 
J

Jester98x

Christina said:
Hello !!
Hi


I want a link on my vb.net web application, which when clicked, popUp's
up and shows a msg.
AFAIK, Javascript is the best way to go.

Yep, javascript is about as good as it gets
So I created an asp:hyperlink, and on its 'on click' event, I have
something like:

Is there a reason for using asp:hyperlink rather than a simple HTML <a
href? i.e. is the link dynamically generated from code?

If memory servers me I think you can use onclientclick to call a
javascript function to poupup the window. e.g. onclientclick="return
showAPopUp(messageString);" and have showAPopUp return false to prevent
even bubbling. This would also prevent the back button causing the
window to reappear as it is managed client side and not by the server.

Page.RegisterStartupScript("myWinName", showAPopUp(messageString),
where, showAPopUp is a code-behind function which has
window.Open(....). messageString is a string that I am building when
the click event occurs.

I have 2 problems :
1) When the 'on Click' event fires, it posts back the page (I beleive,
its posting it to the server). But I am trying to use client sides
scripting to avoid server posts. Does Page.RegisterStartupScript post
data to the server ? If yes, is there a way I can do this without
posting it to the server ?


As mentioned above try not to use asp:hyperlink unless there is a
reason to do so, if you do use the onclientclick option rather than
onclick.
2) In the same link mentioned above, this is the sequence i am
following, which creates a problem.
i click the hyperlink, it opens a pop-up, i close it, go to next page.
Now, when I click IE's back button, instead of showing just the
previous page, it shows me the popup first. Is there a way I can avoid
this too ?

Using the above mentioned method should fix this.
Thanks !!

Your welcome.

Steve
 
C

Christina

Thanx guys for your help !!

Sorry, there was a typo error - I am using <asp:linkbutton
id=lbShowPopUp> and NOT hyperlink.

When clicking on it, the vb.net code executed is below :

Private Sub lbShowPopUp_Click(...)
sMsgStr as string = "Some damn string with hyperlinks and many
formatting etc"
Page.RegisterStartupScript("newWin", popUpWindow(sMsgStr)
End Sub

popUpWindow(message) is in the code-behind, which does specific
formating of the page...


Jester98x, I am using <a onclick="popUpWindow('Some msg here')> in some
cases in the same page. But the case in which I am using
<asp:linkbutton>, its a long string and also fetches some values from
config file (passing configs value to code behind, I havent used it),
so to avoid messing up code-behind, I am using vb.net code. I am open
to other suggestions too, if its possible in my scenario.


<asp:linkbutton id=lbShowPopUp> when clicked, these are steps that are
executed:
1> page_load
2) Private Sub lbShowPopUp_Click(...)

So the page refreshes. This is unlike <a> which doesnt refresh page.

Cowboy, didnt you encounter this problem ? You said u used something
similiar which dint refresh the page, was it -
attribues.add("onClick")... or something similar to lbShowPopUp_Click
()?

Thanks again!!
Chris
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top