How to use Skin.AddPageMessage() method? - c#

I am developing a DNN module and I want to display an info message at the top of my ContentPane, not above the actual module. I have found that DotNetNuke.UI.Skins.Skin.AddPageMessage() should just do the thing. I am not getting the behavior I want though, the message just won't display at all.
There are few overloads of this method, one group accepting a Page object, the other one taking a Skin object.
public static void AddPageMessage(Page page, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)
public static void AddPageMessage(Skin skin, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)
I did take a look into the DNN source and found out that in the end they're actually using the same private static AddPageMessage(...) method, which just looks for a ContentPane within the provided control and adds a new ModuleMessage to the collection of its controls.
What should I pass as a Page or Skin parameter to get this correclty working?
Thanks ...

The private AddPageMessage method takes a fairly ambiguous "Control" as the first parameter. I believe that needs to be the current Skin, as it does a FindControl for ContentPane.
Doing something like this should get you a reference to the current skin:
var skin = Skin.GetSkin((PageBase)this.Page);
Skin.AddPageMessage(skin, "Header", "Message", ModuleMessageType.GreenSuccess);

the reason why the messages are not showing up is that you turned on "enable partial rendering" in the controlssetting of the modulecontrols.
If you are using AJAX (this is happening if you set the partial rendering to true) the DNN modulemessages are turned off from DNN itselfe.
Its enough if you have turned the partial rendering on just 1 control (dont have to be your control where you are acting from) on your page. DNN will wrap the whole page into ajax script manager and messages are not working anymore.
*EDIT 26.04.2012 10:45:
You can get the current ScriptManager by executing the following Code for example in you Page_Load(). If the manager is null, you dont have ajax enabled and the modulemessages should work. If bIsAjaxEnabled is true the modulemessages are disabled.
ScriptManager manager = AJAX.GetScriptManager(Page);
if (manager != null)
{
bool bIsAjaxEnabled = manager.SupportsPartialRendering;
}

Related

How can I tell FindsBy to search elements on this particular sites

I've started learning Selenium Webdriver. It seems pretty easy but I'm not sure how to use PageObject Pattern. I understand the idea, I guess, but I don't know how to map many pages in one project. For example: the site contains many subsites (i.e. login page, create an account page) and I'd like to create PageObject for each of them. When I execute my script, I'm getting messages that elements haven't been found. What should I do? Should I create a separete drviers or what?
Seems that you are doing everything correct: create a new object for each page. Create different objects for common elements that are the same on a lot of pages (like footer, header menu, etc.).
Then to combine page objects, first you need to start somewhere. For example from you main page. So use the MainPageObj to interact wit the main page. As soon as you navigate to another page you need to use a method in your MainPageObj class.
This method must return a page object of the new page. So if you open a Login page from the main page then your method OpenLoginPage() should return LoginPageObj.
Example: MainPageObj and LoginPageObj are page object classes.
MainPageObj class has method:
public LoginPageObj OpenLoginPage()
{
LoginButton.Click();
return new LoginPageObj();
}
So use this method in this way:
MainPageObj mainPage = new MainPageObj ();
LoginPageObj loginPage = mainPage.OpenLoginPage();
Simple?)
If you want to make it more beautifyl then add static class Pages and add static methods for each page object you have to this class. Each method must return a new instance of your specific page object.
Example:
public static class RealSites
{
public static class Kinopoisk
{
public static Kinopoisk.MainPage MainPage
{
get { return new Kinopoisk.MainPage(); }
}
}
}
And in your tests use it this way:
Pages.RealSites.Kinopoisk.MainPage.OpenMoviePage(url);
Pages.RealSites.Kinopoisk.MoviePage.DoSomethigElseMethod();
You can refer this link to understand page object model and after this you can also create for your application
http://www.seleniumeasy.com/selenium-tutorials/simple-page-object-model-framework-example
If you want to learn then selenium easy is best site to learn for beginners.

How do access the tab details in C# from Umbraco 7?

Please see following image.
Umbraco7 screen
I am using Umbraco 7. You can see in the image that I have 'General Messages' tab.
I have saved all error messages in that and i need to access these error messages from the code, can I do that in Csharp ?
I'm going to assume that you have a template assigned to the sign up page, and that you want to get at the messages on that View.
That being the case, you can use either:
#Umbraco.Field("yourPropertyAliasHere")
or
#Model.Content.GetPropertyValue("yourPropertyAliasHere")
The main difference is that Umbraco.Field has a bunch of useful additional parameters for things like recursive lookup.
If you want get at the properties from within some random C# in your Umbraco site that isn't related t the actual signup page, assuming you have an Umbraco Helper, you can do the following:
var page = Umbraco.TypedContent(1234); //replace '1234' with the id of your signup page!
var message = page.GetPropertyValue<string>("yourPropertyAliasHere");

Moving data from one web form to another ASP.NET C#

I am trying to move the content of a textbox on the from StudentRegistration to the form MyProfile by following a tutorial on YouTube. However when I try to reference the StudentRegitration Page in my code, I get the error that the type or namespace cannot be found.
In the tutorial I can see that in their code they have a namespace, however my website does not. Could anyone tell me what to do in order to be able to reference StudentRegistration without getting an error?
I should have stated that I have a website not a web app. I have found that websites do not have a default namespace. How would I go about accessing the StudentRegistration without referencing a namespace?
public partial class MyProfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
StudentRegistration LastPage = (StudentRegistration)Context.Handler;
lblEmail.Text = StudentRegistration.STextBoxEm;
}
}
}
Rather than answer your question directly, I'd like to point out another issue with your code that will probably prevent it from working. You should refer to the documentation on the PreviousPage property at: http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage%28v=vs.110%29.aspx
It does NOT work like this:
user visits /StudentRegistration.aspx
user does stuff
user submits the form on /StudentRegistration.aspx
server redirects the user to /MyProfile.aspx
MyProfile class knows that PreviousPage = the class from /StudentRegistration.aspx
Instead, the description from the msdn reference page linked above stipulates that the PreviousPage property only works on this scenario:
user visits /StudentRegistration.aspx
user does some stuff
user submits form on /StudentRegistration.aspx
server transfers request to the MyProfile class
this does not mean that the url has changed to /MyProfile.aspx for the user, this means that the server is going to treat the current request to /StudentRegistration.aspx as if it were actually a request to /MyProfile.aspx
the user ends up seeing the result of what would normally be /MyProfile.aspx on /StudentRegistration.aspx
Now, your code may actually want that, but the fact that you have:
if (PreviousPage != null)
{
StudentRegistration LastPage = (StudentRegistration)Context.Handler;
// this should be
// StudentRegistration LastPage = (StudentRegistration)PreviousPage;
}
makes me think that you have misinterpreted the somewhat misleadingly named PreviousPage property. For a sample of how to persist state across multiple page loads in .NET, I would recommend reading up on SessionState. It has a somewhat complicated name, but does more of what you would want in this scenario:
http://msdn.microsoft.com/en-us/library/ms178581%28v=vs.100%29.aspx
An added bonus is that you do not need to reference one class from another, so you fix your current bug later on. Additionally, even if you did resolve your potential namespace error, the issue that I outlined earlier will cause the value of the text field to be blank if your code is working as I suspect.
You are sending data from a source to a target - e.g. StudentRegistration -> MyProfile
You have options because at the end of the day, it is HTTP. Aside from "persistence" (Session), and the tutorial you are following, a "simpler" way is to use ButtonPostBackUrl.
All it means is that you are POSTing data to the target page. The target page (MyProfile) will have to validate and parse the posted data (Request.Form). This way you don't have to manage things like Session state.

Central page for error messages

In my ASP.NET C# application, there are many different error messages that I'd like to display.
The way I display my error message is by pop by via:
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('My error message here');", true);
return;
Since there are many different error messages (some repeated across pages) and I have so many different pages in my application - I'd like to put all the error message on a centralized page and reference to it somehow - so that when I need to change my error message, I only need to change in one page and not across ALL the pages.
What's the best way to do this?
I imagine I need to create a .cs page? And have a different ID for each of the error messages.
This seems like a very simple thing to do but I am a bit lost as to how to start on it.
Can someone advice the best way to do this?
Thanks.
I would add extension method to show the alerts and keep all the exception strings in resource file. then I can call the method as below
USAGE
this.ShowAlert(Resource1.MyException);
EXTENSION METHOD
using System;
using System.Web.UI;
namespace WebApplication1
{
public static class Extensions
{
public static void ShowAlert(this Control control, string message)
{
if (!control.Page.ClientScript.IsClientScriptBlockRegistered("msgbox"))
{
var script = String.Format("alert('{0}');", message);
control.Page.ClientScript.RegisterStartupScript(control.Page.GetType(), "msgbox", script, true);
}
}
}
}
Add resource file to your project and enter messages as string entries with meaning full names.
Since you appear to display JavaScript error messages I would create a JS include file and define the JS methods there. That way you can reuse the methods on all pages that include the JS file.
https://softwareengineering.stackexchange.com/questions/91242/what-is-the-best-way-to-include-javascript-file-using-script-tag
JS method can be defined in
* the Master Page
* in the custom base class inherited by all the pages.

How to send debug text from C# class to ASP.NET page

I am working on a C# class that is a part of my ASP.Net Web Site.
Is there a simple way to output some log/debugging text to the top of the page. My class does NOT inherit from Page. I want to display variable values, etc.
The class represents an Exam object that I use in some of my aspx pages. The variables that I want to display are private and therefore inaccessible to my aspx pages.
Anywhere in the context of an http request you can reach the current executing page as follows.
Page page = HttpContext.Current.Handler as Page;
You are free to cast to your own page type. So you can write debug info to labels, textboxes etc.
you can just do this
HttpContext.Current.Response.Write("your message goes here");
or write a helper method
public static void writeOut(string message) {
HttpContext.Current.Response.Write(message);
}
You can try with Response.Write method
var pathOfYourLog = "";
var log = File.ReadAllLines(pathOfYourLog);
YourHttpContext.Response.Write(log);

Categories

Resources