dealing with dialog box

B

Billy

Hi

I'm really having a hard time dealing with dialog box
under asp.net. I'm trying to create a function that will
register some javascript that ask a question to the user,
using the confirm() function.

Function Confirm(ByVal Msg As String, ByVal TBName As
String, ByVal Pa As Page)

Dim sb As New System.Text.StringBuilder
sb.Append("<script language= javaScript>")
sb.Append("<!-- " & vbCrLf)
sb.Append(" if(confirm(" & """" & Msg & """"
& "))" & vbCrLf)
sb.Append(" {document.getElementById(" & """" &
TBName & """" & ").value='true';}" & vbCrLf)
sb.Append(" else{document.getElementById("
& """" & TBName & """" & ").value='false';}" & vbCrLf)
'sb.Append(" location.reload;" & vbCrLf)
sb.Append("--></script>" & vbCrLf)

' Use StartUpScript because I need to load the tbName
before setting his value

Pa.RegisterStartupScript("Conf", sb.ToString)

End Function

I created this function because I need to ask different
proposition that could transfer the user to different
pages or execute other functions, after some execution in
a Click method of a button for example, depending on the
result of the execution. As i can't execute server code
from the script, I decided to check the result of the
hidden field in the page_load function of the page and to
deal with the decision of the user, depending on the
proposition that has been raised.

Here's some example of what I would like to do...

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

If TBRes.value = 'true' Then

Dim Kind As Int16 = ViewState("Kind")
Select Case Kind
Case 1
Server.Transfer("MyPage.aspx")

Case 2
ExecuteSomeCode()

Case 3
Server.Transfer("MyPage2.aspx")
End Case
End If

[...]

End Sub

Private Sub BNew_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BNew.Click

'Execute Some Code
[...]

Dim Kind As Integer = GetProposition()


Select Case Kind
Case 1
Confirm("Would you like to quit this
page?","TBRes", Me)

Case 2
Confirm("Would you like to add another
one?","TBRes", Me)

[...]
End Select

End Sub

The problem is that the script executes after the
page_load, so the function Page_Load don't see the result
of the decision made by the user. I'd like to know if
there is a way to resolve this, like a javascript
function that would raise a post back, or another
solution would be highly appreciated.

thanks a lot for your time, I think that I'm a bit lost
with this...

Billy
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top