showing alert message in vb.net code

Posted by Shoyebaziz123 under ASP.NET on 7/24/2010 | Views : 24610 | Status : [Member] | Replies : 3
Hi all,
i have make a claas to show alert message

Public Sub UserMsgBox(ByVal sMsg As String)
Dim sb As New StringBuilder
Dim oFormObject As System.Web.UI.Control
sMsg = sMsg.Replace("'", "\'")
sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
sMsg = sMsg.Replace(vbCrLf, "\n")
sMsg = "<script language=javascript>alert(""" & sMsg & """)</script>"
sb = New StringBuilder
sb.Append(sMsg)
For Each oFormObject In Me.Controls
If TypeOf oFormObject Is HtmlForm Then
Exit For
End If
Next
oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))
End Sub

Protected Sub btn_show_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_show.Click
UserMsgBox("Hello .....!")
End Sub

working correctly if i am not using Update panel...... but if i take the button into update panel message does not show why? how i can solve it ?

Thanks in advance




Responses

Posted by: Vuyiswamb on: 7/24/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You dont need to put the button inside the update panel. place it outside and add it as a trigger to the updatepanel as i did below

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>

</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" />
</p>
</form>
</body>
</html>


Thank you for posting at Dotnetfunda
[Administrator]

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 7/26/2010 [Member] Starter

Up
0
Down
use scriptmanager.RegisterclientBlock method


ScriptManager.RegisterClientScriptBlock(this, GetType(), "Exists", "window.setTimeout(\"alert('User successfully created.');\",0);", true);


Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: BangaruBabu on: 7/26/2010 [Member] Starter

Up
0
Down
Under Button Click Write Code as Follows


Page.ClientScript.RegisterStartupScript([GetType], "MyScript", "<script>alert('hiiiii Shoyebaziz123 ')</script>")



BangaruBabu Pureti
http://bangarubabupureti.spaces.live.com/

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response