473,508 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Web Form Class

I am writing a web application for my company (VB.NET). I am adding a custom
web form class to prevent all the code reuse as you can see below...

Public Class UIWebForm
Inherits System.Web.UI.Page

Here I have a Public Sub that will use a ASP Literal on the page to display
a javascript alert message...

Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal

Public Sub ShowAlertMessage(ByVal Message As String)
' Format string properly
Message = FormatJavaScriptMessage(Message)
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub

Public Function FormatJavaScriptMessage(ByVal Message As String) As
String
Message = Message.Replace("'", "\'")
Message = Message.Replace(Convert.ToChar(10), "\n")
Message = Message.Replace(Convert.ToChar(13), "")
Return Message
End Function

I need to drop the ASP Literal control onto my webform as follows to get
this to work...

<script>
<asp:Literal id="ltlAlert" runat="server"
EnableViewState="False"></asp:Literal>
</script>

Is there a way that I can have the above code also enter on my page
automatically so that I do not have to enter it on every page that create.
Can I add when the controls render or anything? I cannot think of the
specific funcitons I would need to call or implement
Nov 19 '05 #1
2 1168
Rather than use a hardcoded label as an alert placeholder, why don't you
just use Page.RegisterStartupScript? and register the alert statement
through there?

bill
"Nick" <nt********@online.nospam> wrote in message
news:30**********************************@microsof t.com...
I am writing a web application for my company (VB.NET). I am adding a custom web form class to prevent all the code reuse as you can see below...

Public Class UIWebForm
Inherits System.Web.UI.Page

Here I have a Public Sub that will use a ASP Literal on the page to display a javascript alert message...

Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal

Public Sub ShowAlertMessage(ByVal Message As String)
' Format string properly
Message = FormatJavaScriptMessage(Message)
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub

Public Function FormatJavaScriptMessage(ByVal Message As String) As String
Message = Message.Replace("'", "\'")
Message = Message.Replace(Convert.ToChar(10), "\n")
Message = Message.Replace(Convert.ToChar(13), "")
Return Message
End Function

I need to drop the ASP Literal control onto my webform as follows to get
this to work...

<script>
<asp:Literal id="ltlAlert" runat="server"
EnableViewState="False"></asp:Literal>
</script>

Is there a way that I can have the above code also enter on my page
automatically so that I do not have to enter it on every page that create.
Can I add when the controls render or anything? I cannot think of the
specific funcitons I would need to call or implement

Nov 19 '05 #2
Hi Welcome to ASPNET newsgroup.

As for the displaying alert message in asp.net page you mentioned, I think
William's suggestion on using
Page.RegisterStartupScript function is good. This is a member fucntion of
Page class, however it is not automatically displayed in VB.NET IDE , we
can manually type it in our code. Also, it's better to encapsualte it into
a Page fucntion (in a base page class) so that we can resue it in other
concrete pages, for example:
Public Sub MsgBox(ByVal msg As String)
Page.RegisterStartupScript("msg_script", _
String.Format("<script
language='javascript'>alert('{0}');</script>", msg) _
)

End Sub

Then, in our postback event, we can use the following code to output the
scriptcode which displaying an alert msgbox

Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
MsgBox("hello aspnet!")

End Sub

HTH. Thanks,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4743
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event...
3
1963
by: Frank Wisniewski | last post by:
I have the following persudo code: //My Form Class class Form1 { //Local Variable for my custom object private MyCustomObject1 //Constructor for Form Class public Constructor{
1
1624
by: Vagabond Software | last post by:
I am creating a custom datagrid based, in part, from someone else's code. The author declared a derived datagrid class in a windows form, then declared a derived ColumnStyle class, in the same form,...
6
2210
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
6
1567
by: Steve Amey | last post by:
Hi all I want to be able to throw a custom error up the call stack. I have looked around and it seems as though it's possible, but I can't get it to work :o( Below is some sample code. ...
2
2418
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
19
4891
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
4
2773
by: Suresh | last post by:
Is there any way to access the custom properties of a master page from the aspx form? I know the custom properties of a master page can be accessed from the aspx.cs partial class by specifying...
15
6474
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
4
2464
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.