Javascript popup and server code

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

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
 
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. said:
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
 

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

Back
Top