I have an InfoPath form with codebehind which is going to be hosted in an XmlFormView control on a page in a SharePoint 2007 site.
I will not be able to use codebehind on the page which is hosting the XmlFormView.
Is there any way to access the current HttpContext from the codebehind of the InfoPath form?
Or is there any way to obtain the parameters in the url of the page from within the codebehind of the InfoPath form?
Well, why don't u use e.InputParameters in FormEvents_Loading event?
Something like that:
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
string someGETStringValue= string.Empty;
if (e.InputParameters.TryGetValue("SomeGETStringValue", out someGETStringValue)) {
}
}
Also, please, check out ahi acticle - LoadingEventArgs.InputParameters Property.
I think it would be helpful.
Related
I am a student who is doing up a simple website in asp.net. My problem is, I wish to integrate Paypal on one of the pages, but asp.net has the ridiculous <form runat="server"> that is getting in my way. I am building a simple site layout using blueprint css, a very basic three-column layout. However, I need my main content section to be able to use the paypal form (buy now button), and the other areas of the site to use user controls, which I presume requires them to be wrapped in that irritating form tag. In fact, I would like to have a sitemap path control at the top of the main section of the site: something very basic. How might I achieve that? My problem is: I can't put the Paypal button in the form, and I don't know how to shift a 4th div into place. I am not even sure how divs and forms stack on each other.
Could I have some help please?
The page with the problem is: http://clubofpep.org/sandbox/sandbox_Alumni.aspx.
Contrary to popular belief, you can have more than one form on ASP.Net webforms pages. What you cannot do is have more than one form with runat="server", nest a second form inside ASP.Net's main form, or use asp.net server controls outside the main form.
Therefore, to integrate a separate paypal form with the rest of an asp.net webforms page, you have to make sure that you can put it either before or after all of the asp.net web controls on the page, and then edit the aspx markup to make sure your paypal form is completely outside of asp.net's form.
The other thing is that a quick web search shows a multitude of paypal controls written for asp.net that will work with the required asp.net form to submit the payment. You could always try one of those.
namespace CustomForm
{
public class GhostForm : System.Web.UI.HtmlControls.HtmlForm
{
protected bool _render;
public bool RenderFormTag
{
get { return _render; }
set { _render = value; }
}
public GhostForm()
{
//By default, show the form tag
_render = true;
}
protected override void RenderBeginTag(HtmlTextWriter writer)
{
//Only render the tag when _render is set to true
if (_render)
base.RenderBeginTag(writer);
}
protected override void RenderEndTag(HtmlTextWriter writer)
{
//Only render the tag when _render is set to true
if (_render)
base.RenderEndTag(writer);
}
}
}
USAGE:
ASPX:
<%# Register TagPrefix="CF" Namespace="CustomForm" Assembly="CustomForm" %>
<body>
<CF:GhostForm id="mainForm" runat="server">
...
</body>
<img src="https://www.sandbox.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"> <asp:Button ID="checkoutBtn" runat="server" OnClick="CheckButton_Click"
Text="Checkout" Width="100" CausesValidation="false" />
Code-Behind:
protected void Page_Load(object sender, EventArgs e)
{
...
// Workaround for PayPal form problem
GhostForm mainForm = new GhostForm();
mainForm.RenderFormTag = false;
// Go ahead and submit to PayPal :)
}
I would like to change dynamically the page theme in a MVC 2 Application.
I found several solutions, but I want to use this method: in the Global.asax, change the current page theme:
protected void Application_PreRequestHandlerExecute(object sender, System.EventArgs e)
{
// cast the current handler to a page object
Page p = HttpContext.Current.Handler as Page;
if (p != null)
{
string strTheme = "Theme1";
if (Convert.ToString(HttpContext.Current.Session["THEME"]) != string.Empty)
strTheme = Convert.ToString(HttpContext.Current.Session["THEME"]);
p.StyleSheetTheme = strTheme;
}
}
But this code always returns null in "p"...
I've also tried a similar code using the event PreRequestHandlerExecute in a HttpModule and the PreInit event of a page, but the code
HttpContext.Current.Handler as Page
always returns null.
Can anyone help me?
Thank you in advance.
I don't use baked in themes, but I do use jQuery UI themes. The way I handle it is in my master page I have logic that gets the current theme from a common viewmodel. The master page is strongly typed to this view model. The common viewmodel properties are updated from user preferences and other sources in a common base controller that all my controllers inherit. I do this in OnActionExecuted. I check if the result is a ViewResult, then cast the result from ViewData on the ActionExecutedContext.Result property to my common view model and set the property. The master page uses the value of the property to build the url for the CSS file.
Model
public abstract class CommonViewModel
{
public string Theme { get; set; }
// ...
}
Controller
public abstract class BaseController : Controller
{
public override void OnActionExecuted( ActionExecutedContext context )
{
if (context.Result is ViewResult)
{
var model = ((ViewResult)context.Result).ViewData.Model as CommonViewModel;
if (model != null)
{
var preferences = ...get from database for current user...
model.Theme = preferences.Theme;
}
}
}
}
Master note it uses a custom HtmlHelper to generate the stylesheet link, you could
do it by hand.
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<...CommonViewModel>" >
<%: Html.Stylesheet( "themes/" + Model.Theme + ".css" ) %>
The technique you are talking about works for standard asp.net, not asp.net MVC. The reason is that (in general) asp.net MVC does not use the web control model that standard asp.net does, and as such there is nothing to interpret the theme setting.
#tvanfosson has some great advice. Just remember that with MVC, you have much more control over things.. but that also means you have to do more work to get some of the features that standard asp.net provides for free. MVC makes many things easier, but this is not one of them.
I have an usercontrol with fck editor for allowing user to add note in my aspx page, which allows the user all kind of text formatting.My need is that I have to access user control from the code behind and collect the content as the same format some one has entered in the fck editor.How can I do this?
I'll elaborate on Brian's answer. You need to expose the content from the UserControl by adding a public property:
public string Content
{
get
{
return editor.Content;
}
}
Then to get the content from the user control, just called the property from the Page's code beind:
protected void Page_Load(object sender, EventArgs e)
{
string content = this.UserControl1.Content;
}
In the page, the page code-behind should be able to use it directly like:
this.uc1.<uc code-behind properties or methods>
So you can expose things from your user control by adding public properties or methods.
I have some experience of using paypal with an asp.net website, however this issue has me really stumped.
Root of the problem: You cant embed the html form for the paypal button inside your page form.
Original solution: Originally my website was using multiple aspx pages so I could simply arrange my form tags so that they weren't embedded inside one another.
My website now uses a master aspx page which draws in different ascx controls. This means that I do not have the option of arranging the form tags around the page so need a work around.
NB. I have looked all over the place for simple solutions but it is a jungle out there, paypal is a nightmare. I did find something on ghost form which is all in c#. Might help...
Thanks in advance for any help....
Submit the PayPal information using their APIs rather than submitting a form directly to them.
That way you can keep everything as part of a single form and add a little more robustness around the PayPal input and validation.
PayPal: SDKs and Downloads
Had this issue with another payment provider also. You could either use their API, or you could work around it by:
Making the checkout button a standard imagebutton
Running something like ClientScript.RegisterStartupScript() to output both HTML and Javascript. The HTML should be the actual form with all hidden fields and proper id. The javascript is code which would execute on page load and submit the page.
i.e. ClientScript.RegisterStartupScript(Me.GetType(), "PaypalSubmit", "<AllMarkUp><GoesHere><script>And.Javascript</script>", False)
Hope this helps, otherwise you could use the web service API. By taking this approach you are performing a postback, outputting the HTML form (outside the .NET form because it is at the bottom of the page) and then relying on the javascript to actually submit it.
Here's something that will work for you. In your code-behind:
// Workaround for PayPal form problem
CustomForm mainForm = new CustomForm();
mainForm.RenderFormTag = false;
Create a custom form class which overrides the HtmlForm class:
public class CustomForm : System.Web.UI.HtmlControls.HtmlForm
{
protected bool _render;
public bool RenderFormTag
{
get { return _render; }
set { _render = value; }
}
public CustomForm()
{
//By default, show the form tag
_render = true;
}
protected override void RenderBeginTag(HtmlTextWriter writer)
{
//Only render the tag when _render is set to true
if (_render)
base.RenderBeginTag(writer);
}
protected override void RenderEndTag(HtmlTextWriter writer)
{
//Only render the tag when _render is set to true
if (_render)
base.RenderEndTag(writer);
}
}
In ASP.net 2.0, the PreviousPage property of a web page does not have a ViewState collection. I want to use this collection to transfer information between pages.
View State is exclusive to the page.
If you want to transfer items,
you can persist the data in a database, file, forms auth ticket or other cookie (Dont use Session or HttpContext.Current.Cache if you can help it)
do a cross page post - from your first page, post back to the second page (and get the details from HttpContext.Current.Request.Form[] collection)
put the values in a query string
Use HttpContext.Current.Items instead...ViewState is only good for the page it is on.
You can avoid using PreviousPageType directive, by using some base page class that can hold your object.
For example you have class
public class BaseCrossPage:System.Web.UI.Page
{
public List<Guid> Invitees = new List<Guid>();
}
So if first page derive from this class
public partial class Default : BaseCrossPage
{
protected void Page_Load(object sender, EventArgs e)
{
this.Invitees = LoadInvitees();
}
}
Then the page that you have posted to can access that object, assuming that previous page derived from BaseCrossPage...
public partial class secondPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BaseCrossPage p = (BaseCrossPage)PreviousPage;
List<Guid> Invitees = p.InvitedTeams
}
}
kind of "viewstate" between pages...
You can't directly. (See http://msdn2.microsoft.com/en-us/library/ms178139(vs.80).aspx
Here's what you can do -
Create public properties on the first page exposing the information you want to share. On the second page, set the PreviousPageType to the first page in the header of aspx file:
<%# previouspagetype virtualpath="~/firstpage.aspx" %>
Then, get the values of these properties in the Load event of the second page:
If (Not MyBase.IsPostBack) Then
_someValue = Me.PreviousPage.SomeValue
End If