Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript popup and server code

tshad
Guest
 
Posts: n/a
#1: Nov 19 '05
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



Ken Dopierala Jr.
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Javascript popup and server code


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" <tscheiderich@ftsolutions.com> wrote in message
news:%23AZB$epJFHA.2576@TK2MSFTNGP15.phx.gbl...[color=blue]
> I don't know if this can be done. It is a coordination with my client[/color]
side[color=blue]
> vs my server side code.
>
> I can create a popup fine:
>
> Dim myNextButton As ImageButton =
>[/color]
CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("DownQuesti
on"),ImageButton)[color=blue]
> 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[/color]
congratulations[color=blue]
> message.
>
> My problem is that I need to check to see if a radiobutton has been[/color]
pressed[color=blue]
> 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[/color]
to[color=blue]
> my button as it has already been pushed and the page is already in[/color]
postback[color=blue]
> mode.
>
> Is there a way to do this?
>
> Thanks,
>
> Tom
>
>[/color]


tshad
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Javascript popup and server code


"Ken Dopierala Jr." <kdopierala2@wi.rr.com> wrote in message
news:uke9cksJFHA.2628@tk2msftngp13.phx.gbl...[color=blue]
> 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.[/color]

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[color=blue]
> 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" <tscheiderich@ftsolutions.com> wrote in message
> news:%23AZB$epJFHA.2576@TK2MSFTNGP15.phx.gbl...[color=green]
>> I don't know if this can be done. It is a coordination with my client[/color]
> side[color=green]
>> vs my server side code.
>>
>> I can create a popup fine:
>>
>> Dim myNextButton As ImageButton =
>>[/color]
> CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("DownQuesti
> on"),ImageButton)[color=green]
>> 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[/color]
> congratulations[color=green]
>> message.
>>
>> My problem is that I need to check to see if a radiobutton has been[/color]
> pressed[color=green]
>> 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[/color]
> to[color=green]
>> my button as it has already been pushed and the page is already in[/color]
> postback[color=green]
>> mode.
>>
>> Is there a way to do this?
>>
>> Thanks,
>>
>> Tom
>>
>>[/color]
>
>[/color]


Closed Thread