Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

reloading pages

Posted on 2005-04-22
18
Medium Priority
?
277 Views
Last Modified: 2010-04-07
I have a class, clsShort, that has it's attributes loaded from a database. This class amongst other items, it has a button. This button is a delete button that will remove that record from the database. I have another class, clsShortsLog, that creates an array of clsShort and displays all of the information, including the button, in a table. When I click the button, the event from clsShort fires, and the short is removed. However, my table is not updated. How can I "refresh" the page after this button is clicked?
0
Comment
Question by:fizch
  • 9
  • 6
  • 3
18 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13844616
To refresh,
[VB.NET]
Response.Redirect(Request.RawUrl,True)

[C#]
Response.Redirect(Request.RawUrl,true);
0
 
LVL 33

Expert Comment

by:raterus
ID: 13844641
You sound like you are coming from a winforms background, where these kind of things automatically happen for you if you've hooked your controls up to a database.  This is not the case with asp.net / webcontrols.  If you want the table updated, you must call the method again that filled it in the first place.
0
 
LVL 6

Author Comment

by:fizch
ID: 13844925
b1xml2,
clsShort, the class that contains the button, inherits from another class so I do not have access to System.Web.UI.Page to utilize response.redirect

raterus,
the method that is called to build that table is in an implenting class. clsShortsLog has no idea that the event from clsShort fired.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Accepted Solution

by:
raterus earned 1200 total points
ID: 13845019
so tell it!, raise an event, which you handle in the calling class, example:

Public Class clsShort
  Public Event DeletedSomething

  Public Sub Delete
    <put your current delete code here>

    RaiseEvent DeletedSomething
  End Sub
End Class

--

Now in clsShortsLog, declare your reference "WithEvents", and make a sub like this
Public Class clsShortsLog
  Public Withevents ShortStuff as clsShort

  Public Sub shortstuff_DeletedSomething(sender as object, e as eventargs) Handles ShortStuff.DeletedSomething
    'do what you need to do
  End Sub
End Class
0
 
LVL 6

Author Comment

by:fizch
ID: 13845107
How do I create the object with events in C#? I am sorry, I should have clarified that earlier.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845139
b1xml2,
>>>
clsShort, the class that contains the button, inherits from another class so I do not have access to System.Web.UI.Page to utilize response.redirect
<<<
never true

System.Web.HttpContext.Current.Request.Redirect(...);
0
 
LVL 33

Expert Comment

by:raterus
ID: 13845143
That's a question for a C#'er, the events work the same, but are set up rather differently.  Search google for "C# custom events" and you'll find a bunch of links on the subject, here is one of them,

http://www.devarticles.com/c/a/C-Sharp/Creating-Custom-Delegates-and-Events-in-C-sharp/
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845147
i mean System.Web.HttpContext.Current.Response.Redirect(...);
0
 
LVL 33

Expert Comment

by:raterus
ID: 13845239
the event handling solution I proposed is the best solution here, redirecting to the page you're already on is a waste of resources and time on your users part.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845271
a waste of resources depends entirely on the asker's circumstances, it is not for any of us to tell him so. sometimes, there is a tight deadline and he wants something that whilst not the most elegant of ways, does not require an immediate rewrite of his code.
0
 
LVL 33

Expert Comment

by:raterus
ID: 13845348
Actually it doesn't, a waste of resources is a waste of resources any way you look at it.  If your boss is riding you and you needed this done yesterday, then by all means use the statically hacked method to access the current HttpContext and redirect the page.  Be sure to sweep under the rug any good object-oriented design principles you have stuck to so far while designing this program.  Just because it works doesn't mean you should do it, nor does it mean it's the correct way to do things.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845406
again, whilst it is excellent to design it from bottom up, let me assure you from what I have seen in the questions posted by a lot of askers, there are really very few who can understand the need for encapsulation, for event-driven methodology and even for that matter the use of interfaces to allow pages to talk to user controls in a controlled way.

In my observations, there is a definitive difference in general (not applying specifically) between the OO understanding of a C# and VB.NET (oh the Hungarian Notation is still alive).

You made the assertion that the event handling solution is the best, but do you know what else may be happening. I have learnt that whilst perfection is a desirable goal, sometimes the mess in existing code inihibits that. Let him decide what is best for him with him weighing your words against his need.

In the real world, perfect code is not achievable.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845411
between the OO understanding of a C# and VB.NET (oh the Hungarian Notation is still alive) programmer...
0
 
LVL 6

Author Comment

by:fizch
ID: 13845459
I have to agree with raterus. His solution does maintain the OO design of my application, and having the page redirect everytime that button is hit does cause a bit more over head. Both options work, however, I would prefer to stick with the OO design.

b1xml2, I understand what you are saying about most users that post here. Most of them do not understand what a class is, not to mention inheritance and encapsulation. However, you should be able to tell from my post that is not the case here.
0
 
LVL 33

Expert Comment

by:raterus
ID: 13845591
Someone that understands OO!  Very rare indeed...  Unfortunately most experts on this site don't know OO either, at least enough to help you <sigh>
0
 
LVL 23

Assisted Solution

by:b1xml2
b1xml2 earned 800 total points
ID: 13845719
simple to implement custom events, here we are using the default EventHandler

public event EventHandler ItemChanged;

protected void OnItemChanged()
{
      EventHandler handler = this.ItemChanged as EventHandler;
      if (handler != null)
            handler(this,EventArgs.Empty);
}


and in your class that loads the Array, you hook onto the events accordingly:
      
this.<classname_instnace>.ItemChange += new EventHandler(this.ProcessItemChanged);

private void ProcessItemChanged(object sender,EventArgs e)
{
      // do whatever.
}


if your class inherits from the ComponentModel class
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845748
remove this if your class inherits from the ComponentModel class
========
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13845766
the way to raise the event is to have the instance class call OnItemChanged for example. If the class is marked as sealed, then it is pointless to mark this as protected, you can then mark it as private. If any of your classes inherit from the Control Class or ComponentModel Class, you can use the Events Property to implement events more efficiently than VB.NET
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question