Newbie, how to display a messagebox always on top


V

verci

Hi, sorry if this seems stupid, please have patience.

I'm running Win XP sp2, VS 2005 Tem, SQL Sever 2005, I've been using a
gridview to display my DB information, on the Gridview_RowUpadating event
handler I validate if the value entered already exist en the DB using the
following.

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating

Dim valor As String = e.NewValues("ProductName").ToString

If RunQueryDr(valor) = True Then

e.Cancel = True

MsgBox("This value already exist!", MsgBoxStyle.ApplicationModal +
MsgBoxStyle.Critical, "Error")

Return

End If

End Sub

I want to display the message box always on top of other windows, so the
user can't minimize it or even worst keep trying to update the record and
thus opening various error message boxes, I've tried the JavaScript
openwindow and alert functions with no success.

Thanks
 
Ad

Advertisements

E

Eliyahu Goldin

A simple answer is that javascript alert function is the way to go. You can
pass the message to show to the client-side where it can be picked up and
displayed. The standard way of passing information between server and client
is using hidden input controls. Put this line in your web form:
<input type="hidden" runat="server" id="inhMessage"/>

The server code will set the message as

inhMessage.Value="This value already exist!"

The client code will access it as
<script>
function checkMessage(){
if(myForm.inhMessage.Value<>'')
{
alert(myForm.inhMessage.Value);
myForm.inhMessage.Value='';
}
}
</script>
....
<body onload='checkMessage()'/>
 
Ad

Advertisements

E

Eliyahu Goldin

Javascript is case-sencitive. Should be

function checkMessage(){
if(myForm.inhMessage.value<>'')
{
alert(myForm.inhMessage.value);
myForm.inhMessage.value='';
}
}

If you still get error messages, specify the error text.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


verci said:
Hi
Can you please take a look at my code , what am I doing wrong? I get 2
error messages :


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb"
Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head runat="server">

<title>Untitled Page</title>

<script>

function checkMessage(){

if(myForm.inhMessage.Value<>'')

{

alert(myForm.inhMessage.Value);

myForm.inhMessage.Value='';

}

}

</script>

</head>

<body onload='checkMessage()'>

<form id="form1" runat="server">

<input type="hidden" runat="server" id="inhMessage"/>

<div>

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"

DataKeyNames="ProductID" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False"

ReadOnly="True" SortExpression="ProductID" />

<asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">

<EditItemTemplate>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductName")
%>'></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"

ErrorMessage="Valor requerido"
Text="*"></asp:RequiredFieldValidator>&nbsp;

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductName")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:CommandField ShowEditButton="True" />

</Columns>

</asp:GridView>

&nbsp; &nbsp;

<asp:ValidationSummary ID="ValidationSummary1" runat="server"
Style="z-index: 100;

left: 449px; position: absolute; top: 37px" DisplayMode="List"
Font-Bold="True" ShowMessageBox="True" ShowSummary="False" />

&nbsp;

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

SelectCommand="SELECT [ProductID], [ProductName] FROM [Products] order by
ProductID"

UpdateCommand="Update Products set [email protected] where
[email protected]"></asp:SqlDataSource>

</div>

</form>

</body>

</html>



Eliyahu Goldin said:
A simple answer is that javascript alert function is the way to go. You
can
pass the message to show to the client-side where it can be picked up and
displayed. The standard way of passing information between server and
client
is using hidden input controls. Put this line in your web form:
<input type="hidden" runat="server" id="inhMessage"/>

The server code will set the message as

inhMessage.Value="This value already exist!"

The client code will access it as
<script>
function checkMessage(){
if(myForm.inhMessage.Value<>'')
{
alert(myForm.inhMessage.Value);
myForm.inhMessage.Value='';
}
}
</script>
...
<body onload='checkMessage()'/>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


verci said:
Hi, sorry if this seems stupid, please have patience.

I'm running Win XP sp2, VS 2005 Tem, SQL Sever 2005, I've been using a
gridview to display my DB information, on the Gridview_RowUpadating
event
handler I validate if the value entered already exist en the DB using
the
following.

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating

Dim valor As String = e.NewValues("ProductName").ToString

If RunQueryDr(valor) = True Then

e.Cancel = True

MsgBox("This value already exist!", MsgBoxStyle.ApplicationModal +
MsgBoxStyle.Critical, "Error")

Return

End If

End Sub

I want to display the message box always on top of other windows, so the
user can't minimize it or even worst keep trying to update the record
and
thus opening various error message boxes, I've tried the JavaScript
openwindow and alert functions with no success.

Thanks
 

Top