Identifying a usercontrol in the same page in ASP.net - c#

Am using a user control say C in a page say A. So also while doing a submit / or action in the user control ( It contains a grid with edit delete functionality) , control goes to parent page A then only enters to the edit or delete function.
How can i identify that the control has been directed from the user control?
Please help me out.
Thanks in Advance

How about
if (sender is C) // You said your usercontrol is say C
{
//Your Code Here
}

I got a work around . I would like to share it over here.
We can use
this.Parent.FindControl("x").Visible = false;
here x is the div in the parent page which incorporates the user control. Using this i solved my problem instead of tracking the flow.
My problem was like while the user control pops up, one control inside the parent page also get popped up even if its visibility is set to false. I needed to truncate this.
Thanks .

Related

How to access controls on a master page dynamically from another user control, if the web application has nested master page

I have a user control, say control 1, that looks for control2, which is placed on the root master page : Site.Master
And this is how I am getting Control2 from Control 1 now,
MasterPage showMaster = this.Page.Master.Master;
MasterPage siteMaster = showMaster.Master;
Control2= siteMaster.FindControl("Control2");
The above code works fine. But because our application uses nested master pages, I am running into a bit of situation here.
How do I find control 2 dynamically regardless of where I put Control1 in which template? Becasue right now, depends on where I put Control1, and how nested is that template in relation to the Site.Master, I have to change how far up in the chain I get Site.Master in the Control 1 code.
Any good ideas on how I can avoid doing that?
Please advise.
i found a work around with recursively loading the control

FieldValidators and Visual Web Part (Sharepoint 2010)

I have a visual web part (a simple form) with RequiredFieldValidators. But a problem has occured since the field validators block editing of the page. When i press Edit Page in Sharepoint it starts to load then the validators fire and the javascript is stopped.
I found a solution but i cant get it to work.
Like this
public override void CreateChildControls()
{
if(SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
((UserControl)_ctl).EnableValidators(false);
((UserControl)_ctl).EnableValidators(true);
}
//But the _ctl does not exit i only have
Control control = Page.LoadControl(_ascxPath);
A litte advice would help this sharepoint noob a great deal.
The form is just Labels, Inputs, a button, updatepanel and requiredFieldValidators
Can you not just set the ValidationGroup for the validators and button? Like this: http://msdn.microsoft.com/en-us/library/ms227424.aspx
The validators should only fire when the button is pressed.
There is something wrong with your configuration - I tested this configuration and the required field validators definitely don't block editing on the page. Do you want to post your page and your code behind? Might help to troubleshoot the problem.

Accessing a UserControl from different Usercontrol

I am trying to use the already written code which accesses a control from an other control in the following code.
Controls_SearchFeaturedMerchants UCMerchant = (Controls_SearchFeaturedMerchants)this.Parent.FindControl("UCSearchFeaturedMerchants1");
I am wondering what this statement says. Can someone please give me some idea :)
Thanks in advance!
If I understood your question correctly here is the brief:
On a page (ContentPage) is hosting two user controls (UsrCtrl1, UsrCtrl2).
Now "UsrCtrl1" wanted to access some data in the "UsrCtrl2".
For that I'll write code like - "UsrCtrl1" parent is the "ContentPage" that page hosts "UsrCtrl2", so I'll first get the "UsrCtrl2" from the parent page with the following code:
this.Parent.FindControl("UsrCtrl2Name") -> this means current user control which is "UsrCtrl1" and Parent means is the "ContentPage" (it may be parent control or page) in that you are trying to find a contrl with Id "UsrCtrl2Name" (this is the id of the 2nd user control in the content page).
When you use FindContrl method it always returns base type UserControl and you need to cast it to your usercontrol in this case it is of type "UsrCtrl2".
I hope this is clear now.
in plain text it is saying:
Get the Parent Control of the current control and then find UCSearchFeaturedMerchants1 on said control. Cast the result into a Controls_SearchFeaturedMerchants.
Hope that sums it up for you

ASP.Net: User control with content area, it's clearly possible but I need some details

I have seen two suggestions for my original question about whether it is possible to define a content area inside a user control and there are some helpful suggestions i.e.
Passing in content to ASP.NET user control
and
ASP.NET User Control inner content
Now, I like the theory of the latter better than the former just for aesthetic reasons. It seems to make more sense to me but the example given uses two variables content and templateContent that the answerer has not defined in their example code. Without these details I have found that the example does not work. I guess they are properties of the control? Or some such?
EDIT - DETAILS: What I am trying to do
I have need of an ASP.Net user control that conceals some content in a panel inside a placeholder and asks for the input of a code in a visible panel.
Essentially the user will put their code into the provided textbox in Panel A and submit it, it will be checked and, if it is valid, panel B and the locked content will be displayed.
I have done a test where the content was hard coded into panel B but as soon as I need to make the content a generic input it fails. If it were just text or somesuch then I could make it a property of the control, but as it is, in fact, another User Control I am having some difficulty getting this into the "hidden" panel.
Any other workable solutions are also welcome.
EDIT NOTE: The solution I'm trying to implement this in 2.0 I did find a 3.5 solution which I cannot use.
The former example seems workable but I'd prefer to go with the latter if someone could fill in the blanks for me.
Thanks.
Okay, so this is disturbingly easy but many of the tutorials on the web that talk about this kind of thing push to do extravagant things that require the control to parse ListItems or such.
So this solution is purely so that you can build a control that, for whatever reason, has a placeholder in it that could have anything inside it (kind of like a content area on a Master page). In this instance it happens to be because the Panel containing the placeholder is hidden until appropriate input actions have taken place in another panel.
First, you need to add this:
[ParseChildren(true,"Content")]
[PersistChildren(false)]
just above the part of the control which looks like this:
public partial class MyControl : System.Web.UI.UserControl
then in the control scoped declarations at the head of the control you want to declare thus:
private Control _content;
[PersistenceMode(PersistenceMode.InnerProperty)]
public Control Content { get { return _content; } set { _content = value; } }
Finally you need to place the content into the placeholder like this:
phContent.Controls.Add((Control)_content);
That last line goes into the Page_Init event. For reference "phContent" is the name of the place holder where you want the content to appear, like this:
<asp:Panel ID="pnlLockable" runat="server" Visible="False">
<asp:Placeholder runat="server" ID="phContent" />
</asp:Panel>
On the front end the resulting implementation looks like this:
<uc:MyControl runat="server" ID="lockit1">
<Content>
//...your stuff goes here...
</Content>
<uc:MyControl>
Note that I presume that what is inbetween the Content Tags is a root control. This is because I nested another user control in there. I imagine if you put whatever content you want within a panel or placeholder it should be fine.
Also you can read "How to: Create Templated ASP.NET User Controls". Really helpful.

Navigating between DotNetNuke module controls using EditURL() or NavigateURL()

OK I'm new to DotNetNuke and need to write a simple module in DNN that will display an article for everyone, and allow the admin to edit the article/add a new one.
I have a test page that contains a DNN module with one module definition and two controls in that definition. The default control shows the article based on an articleID field in the querystring. You then click a button that is supposed to load the edit control and pass the articleID in the query string.
If I use EditURL() in the onClick the edit control is loaded with the correct articleID, but using the admin skin. If I use Globals.NavigateURL() then the correct skin is shown but my edit control isn't loading in the page.
Any clue as to how to what I'm doing wrong or how to get the edit control loading with the correct skin?
My two methods of switching to the edit control (in my button click event) are listed below:
string newURL = this.EditUrl("articleID", Request.QueryString["articleID"], "EditArticle");
Response.Redirect(newURL);
and
string newURL = Globals.NavigateURL(this.TabId, "EditArticle","articleID="+Request.QueryString["articleID"]);
Response.Redirect(newURL);
Actually you are doing this correctly - the editurl in DNN does load the Admin skin - usually this skin is based on someone administering content so it strips out all other modules and shows the 'basics'. Right or wrong this is what it does.
If you dont want to to do that you could provide a switch in the querystring and show a seperate panel or do a multiview control and show different views based on the switch in the query string.
There are a few other approaches like changing the content area to editing text area with ajax or using popup modal style windows.

Categories

Resources