By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,544 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,544 IT Pros & Developers. It's quick & easy.

Javascript popup and server code

P: n/a
I don't know if this can be done. It is a coordination with my client side
vs my server side code.

I can create a popup fine:

Dim myNextButton As ImageButton =
CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("DownQuestion"),ImageButton)
myNextButton.Attributes.Add("onclick", "return confirm('Are you sure
you want finish this test?');")

This will put a popup on my button that will get processed before the page
posts. If they say "yes" the post happens, if "no", it doesn't.

If it posts, I am going to hide part of the page and show a congratulations
message.

My problem is that I need to check to see if a radiobutton has been pressed
first and one of my global values is set. This means I need to go to my
server side code to check this out and it is too late to attach the popup to
my button as it has already been pushed and the page is already in postback
mode.

Is there a way to do this?

Thanks,

Tom
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Tom,

You could try something like this:

In your code behind put this in your declarations:

Protected WithEvents hidGlobal As System.Web.UI.HtmlControls.HtmlInputHidden

Change your onclick Attribute:

myNextButton.Attributes.Add("onclick", "return MyConfirm();")

Assign your global variable to the hidden field:

hidGlobal.Value = CStr(theglobalvariable)

Now in your .aspx page do this:

Add the input tag:

<input type="hidden" id="hidGlobal" name="hidGlobal" runat="Server">

Then add the JavaScript function:

function MyConfirm() {
if (document.getElementById("radiobuttonid").checked == true) {
if (document.getElementById("hidGlobal").value == "what it should")
{
return confirm('Are you sure you want finish this test?');
}
}
return false;
}

You'll probably need to change that around to correspond to the correct
logic for your radio buttons and global variables but that should set you on
the right track to accomplish what you are trying to do. If you have
anymore questions fire away and watch out for any typos I might've made.
Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I don't know if this can be done. It is a coordination with my client side vs my server side code.

I can create a popup fine:

Dim myNextButton As ImageButton =
CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("DownQuesti
on"),ImageButton) myNextButton.Attributes.Add("onclick", "return confirm('Are you sure
you want finish this test?');")

This will put a popup on my button that will get processed before the page
posts. If they say "yes" the post happens, if "no", it doesn't.

If it posts, I am going to hide part of the page and show a congratulations message.

My problem is that I need to check to see if a radiobutton has been pressed first and one of my global values is set. This means I need to go to my
server side code to check this out and it is too late to attach the popup to my button as it has already been pushed and the page is already in postback mode.

Is there a way to do this?

Thanks,

Tom

Nov 19 '05 #2

P: n/a
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
Hi Tom,

You could try something like this:

In your code behind put this in your declarations:

Protected WithEvents hidGlobal As
System.Web.UI.HtmlControls.HtmlInputHidden

Change your onclick Attribute:

myNextButton.Attributes.Add("onclick", "return MyConfirm();")

Assign your global variable to the hidden field:

hidGlobal.Value = CStr(theglobalvariable)

Now in your .aspx page do this:

Add the input tag:

<input type="hidden" id="hidGlobal" name="hidGlobal" runat="Server">

Then add the JavaScript function:

function MyConfirm() {
if (document.getElementById("radiobuttonid").checked == true) {
if (document.getElementById("hidGlobal").value == "what it should")
{
return confirm('Are you sure you want finish this test?');
}
}
return false;
}

You'll probably need to change that around to correspond to the correct
logic for your radio buttons and global variables but that should set you
on
the right track to accomplish what you are trying to do. If you have
anymore questions fire away and watch out for any typos I might've made.
I'll play around with this.

I should be able to do everything but the "withevents" statement, as I am
not using code-behind at the moment.

Thanks,

Tom Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I don't know if this can be done. It is a coordination with my client

side
vs my server side code.

I can create a popup fine:

Dim myNextButton As ImageButton =

CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("DownQuesti
on"),ImageButton)
myNextButton.Attributes.Add("onclick", "return confirm('Are you
sure
you want finish this test?');")

This will put a popup on my button that will get processed before the
page
posts. If they say "yes" the post happens, if "no", it doesn't.

If it posts, I am going to hide part of the page and show a

congratulations
message.

My problem is that I need to check to see if a radiobutton has been

pressed
first and one of my global values is set. This means I need to go to my
server side code to check this out and it is too late to attach the popup

to
my button as it has already been pushed and the page is already in

postback
mode.

Is there a way to do this?

Thanks,

Tom


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.