FYPJ
asked on
How to call VB Script in VB code?
Hi,
I need to execute my VB code when this happens:
If userName <> dReader2("custID") Then
Response.Redirect("ForumPo sts.aspx?t opicID=" & topicID)
'Execute VB code right here
End If
This is my VB code:
<!-Script to alert user that they can only edit their own post.>
<script language="vbscript">
Function NoWay()
MsgBox("You can only edit your own posts!")
End Function
</script>
How do it call it?
I need to execute my VB code when this happens:
If userName <> dReader2("custID") Then
Response.Redirect("ForumPo
'Execute VB code right here
End If
This is my VB code:
<!-Script to alert user that they can only edit their own post.>
<script language="vbscript">
Function NoWay()
MsgBox("You can only edit your own posts!")
End Function
</script>
How do it call it?
You can use
If userName <> dReader2("custID") Then
ResponseClientScriptBlock ("way", "MsgBox('You can only edit your own posts!')" );
Response.Redirect("ForumPo sts.aspx?t opicID=" & topicID)
End If
but you have to change the places of the response.redirect and the vb execution
B..M
If userName <> dReader2("custID") Then
ResponseClientScriptBlock ("way", "MsgBox('You can only edit your own posts!')" );
Response.Redirect("ForumPo
End If
but you have to change the places of the response.redirect and the vb execution
B..M
ASKER
Hi,
I can't use Timbo87's solution as i dun have an onclick command to run the script.
As for mmarinov, what is ResponseClientScriptBlock?
I can't use Timbo87's solution as i dun have an onclick command to run the script.
As for mmarinov, what is ResponseClientScriptBlock?
ASKER
Sorry i did not fully understand it. Begginner here.
This was wat i tried:
'Form the script that is to be registered at client side.
Dim scriptString As String
scriptString = "<script language=VB> function NoWay()"
scriptString += "MsgBox(""You can only edit your own posts!"")"
scriptString += "End Function"
scriptString += "</script>"
If userName <> dReader2("custID") Then
Response.Redirect("ForumPo sts.aspx?t opicID=" & topicID)
RegisterClientScriptBlock( "clientScr ipt", scriptString)
End If
But still no alert box appeared.
What is the correct way?
This was wat i tried:
'Form the script that is to be registered at client side.
Dim scriptString As String
scriptString = "<script language=VB> function NoWay()"
scriptString += "MsgBox(""You can only edit your own posts!"")"
scriptString += "End Function"
scriptString += "</script>"
If userName <> dReader2("custID") Then
Response.Redirect("ForumPo
RegisterClientScriptBlock(
End If
But still no alert box appeared.
What is the correct way?
try this
Dim scriptString As String
scriptString = "<script language=javascript> function NoWay(){"
scriptString += "if(confirm(""You can only edit your own posts!""))"
scriptString += "{document.location.href=" & "ForumPosts.aspx?topicID=" & topicID & "}"
scriptString += "}"
scriptString += "</script>"
If userName <> dReader2("custID") Then
RegisterClientScriptBlock( "clientScr ipt", scriptString)
End If
B..M
Dim scriptString As String
scriptString = "<script language=javascript> function NoWay(){"
scriptString += "if(confirm(""You can only edit your own posts!""))"
scriptString += "{document.location.href="
scriptString += "}"
scriptString += "</script>"
If userName <> dReader2("custID") Then
RegisterClientScriptBlock(
End If
B..M
ASKER
Hmm... tried ur code but i directs me straight to the page without the alert box.
does it give you client errors ?
i don't think that this will give you something different but try this
scriptString = "<script language=javascript> function NoWay(){"
scriptString += "if(window.confirm('You can only edit your own posts!'))"
scriptString += "{document.location.href=" & "ForumPosts.aspx?topicID=" & topicID & ";}"
scriptString += "}"
scriptString += "</script>"
Unfortunatelly i can not test it :-( right now
i don't think that this will give you something different but try this
scriptString = "<script language=javascript> function NoWay(){"
scriptString += "if(window.confirm('You can only edit your own posts!'))"
scriptString += "{document.location.href="
scriptString += "}"
scriptString += "</script>"
Unfortunatelly i can not test it :-( right now
ASKER
Nope it does not give any error, just directs me right to the page without any alerts.
Still doesn't work.
Thanks for ur effort to help. Can u get back to me soon when u find the solution?
Thanks!
Still doesn't work.
Thanks for ur effort to help. Can u get back to me soon when u find the solution?
Thanks!
i've send it to a friend of mine and this work i've tested
Dim scriptString As String
scriptString = "<script language=javascript>"
scriptString += "if(confirm(""You can only edit your own posts!""))"
scriptString += "{document.location.href=" & """ForumPosts.aspx?topicID =" & topicID & "";}"
scriptString += "</script>"
If IsPostBack Then
RegisterClientScriptBlock( "clientScr ipt", scriptString)
End If
B..M
Dim scriptString As String
scriptString = "<script language=javascript>"
scriptString += "if(confirm(""You can only edit your own posts!""))"
scriptString += "{document.location.href="
scriptString += "</script>"
If IsPostBack Then
RegisterClientScriptBlock(
End If
B..M
ASKER
Nope still doesn't work for me.
Damn this sucks...
Is there anyway i can generate a VB MsgBox from my VB codes without calling a script?
Sorry for the trouble.
Damn this sucks...
Is there anyway i can generate a VB MsgBox from my VB codes without calling a script?
Sorry for the trouble.
i hate the qutes in vb :-(
this line is incorrect :-( scriptString += "{document.location.href=" & """ForumPosts.aspx?topicID =" & topicID & "";}"
it should be
scriptString += "{document.location.href=" & """ForumPosts.aspx?topicID =" & topicID & """;}"
about vb msgbox - i can not tell if it or it is not a way of doing this
i stopped use vb script for clients needs because it is workig only in ie
B..M
this line is incorrect :-( scriptString += "{document.location.href="
it should be
scriptString += "{document.location.href="
about vb msgbox - i can not tell if it or it is not a way of doing this
i stopped use vb script for clients needs because it is workig only in ie
B..M
ASKER
YES!!! Thank u very much it works!
But the confirm box gives the user a choice of yes or no to click, is there a way to edit it to show only 1 button?
But the confirm box gives the user a choice of yes or no to click, is there a way to edit it to show only 1 button?
it is not possible to edit yes/no button but you can use alert instead of confirm
but in this way it won't return true/false value but will acts like a normal mesage
is this what you want ?
B..M
but in this way it won't return true/false value but will acts like a normal mesage
is this what you want ?
B..M
ASKER
Yes thats what i need.
So how do i structure my script so that when the user clicks ok on the alert box i will direcit them to this page?
document.location.href=" & """ForumPosts.aspx?topicID =" & topicID & """;
So how do i structure my script so that when the user clicks ok on the alert box i will direcit them to this page?
document.location.href=" & """ForumPosts.aspx?topicID
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yourWebControl.Attributes.