473,569 Members | 2,845 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.P age

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.W ebControls.Lite ral

Public Sub ShowAlertMessag e(ByVal Message As String)
' Format string properly
Message = FormatJavaScrip tMessage(Messag e)
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub

Public Function FormatJavaScrip tMessage(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 1173
Rather than use a hardcoded label as an alert placeholder, why don't you
just use Page.RegisterSt artupScript? and register the alert statement
through there?

bill
"Nick" <nt********@onl ine.nospam> wrote in message
news:30******** *************** ***********@mic rosoft.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.P age

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.W ebControls.Lite ral

Public Sub ShowAlertMessag e(ByVal Message As String)
' Format string properly
Message = FormatJavaScrip tMessage(Messag e)
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub

Public Function FormatJavaScrip tMessage(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.RegisterSt artupScript 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.RegisterSt artupScript("ms g_script", _
String.Format(" <script
language='javas cript'>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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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
4760
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 Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For...
3
1964
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
1629
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, that accepted his custom grid type as an argument. For example: public class HisCustomGrid : DataGrid { public HisCustomGrid() { } } public...
6
2212
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 class would have CurrentUser property that would hold customer class in session and that was fine for all my situations. Now ASP.NET 2.0 came...
6
1572
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. ------------------------------------------------------------ Public Class MainForm Public Sub Show Form Try
2
2427
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 fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I...
19
4900
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom...
4
2778
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 the MasterType directive on the aspx form. My master page will render a custom navigation menu and I'd like to put in the properties of which tab...
15
6492
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 accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then...
4
2472
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 unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
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 we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.