Using User Control in Master Page - Need Focus - c#

This is the scenario:
I have a Master Page,
In the Master Page I have a user control
In the User Control there is a code that looks like this
<div>
<a id="p1" runat="server">
<asp:Image ID="Img" runat="server" ImageAlign="AbsMiddle" Style="position:relative;
bottom: 0px;" /></a> -<a id="p2" runat="server">
<asp:Label ID="lblRate" runat="server"></asp:Label>
Rates</a>
</div>
Now, when the user clicks on "Rates" it should focus on an item that is another User Control back in the Master Page.
How can I do this?, this is existing code and can not modify the current structure but what is currently happening is that when "Rates" is clicked it postsback with a parameter goto=rates but doesnt do anything.. I need to make so that when it is clicked it focuses on another UserControl in the Master Page. (but this "Rates" link is User Control too)
I tried in my Master Page the following
if(!Page.Postback)
{
if(Request.Params["goto"] == "rates"){
uControl.Focus();
}
}
No luck, please help :(
So to recap:
MasterPage has UserControl -> UserControl has a link that postsback with parameter goto=rates -> back in the MasterPage I need to focus the screen on another UserControl.
I tried to be as clear as I could
Thank you

not all controls supports focus like this. for your user control, you may need build javascript to setup focus.

Looks like you have a not opperator where you should. You should change if(!Page.Postback) to if(Page.Postback).

Related

C# Access asp control from Parent page

I have a parent page containing an iframe, an ASP label and a button.
When the user click on the parent button, it will display some table results inside the iframe.
Now i would like to display the parent label with different text and color depending on the results of the iframe.
So i m trying in the code behind (C#) of the iframe to retrieve the label from the parent and assign it a CssClass. But no matter what i do it always come back with a null reference when trying to find the control from the parent.
Can someone please help?
Parent page code:
<div class="search-row">
<div class="search">
<button id="btnSearch" type="submit" class="button button-block">Search</button>
</div>
<div class="search" style="padding-top: 20px;">
<asp:Label ID="wrapperResponse" CssClass="resp" runat="server">TEST</asp:Label>
</div>
</div>
<div id="iframeDiv">
<iframe name="my_frame" width="100%" height="350px" src="Results.aspx" scrolling="no" frameborder="0"></iframe>
</div>`
The Results.aspx will display a table with some html build dynamically.
Now let s say if resulting Table has one row, i would like Label WrapperReponse to be in Green and says "1 row" but if 2 rows then i would like it to be in Red and says "2 Rows"
In my Results.aspx.cs i tried
String test= String.Format("{0}", Request.Form["wrapperResponse"]);
Label statusResponse = (Label)this.FindControl("wrapperResponse");
Label statusResponse2 = (Label)Parent.FindControl("wrapperResponse");
Any ideas are welcome!
thanks
Well, just a couple of points needed mentioning here. Food for thought.
In order to access the asp label control, you need to do it on the parent page instead of on the results page.
I would suggest you reconsider the design of the page. Do you really have to use the iframe here? Why not place your button and label controls on the results.page directly? Or perhaps make results.aspx as an ASCX user control, so you can embed it on the parent page.
Hope it helps

Modal Popup not firing in C#

I have been trying to get a Modal Popup to work for the last few months. I try and try, and after a while I just give up and find another way to work around it. I am very new to programming and have been doing some helpful things for my department, but in order to make these things viable alternatives I need to get more functionality out of them.
I want to be able to update a row in my SQL server, but the gridview is pulling data from a View, so the built in edit options won't work for me. I was hoping to be able to have a Modal Popup appear on the screen so that I can have the user put the data in and it will build the proper SQL statement to update the row.
I can't even get a Modal Popup with a single line of text to 'popup' though.
At the top of the page I have this:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Then in my main div I have this:
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat=server"></cc1:ToolkitScriptManager>
Then down in the body I have this:
<asp:Button ID="btnTest" runat="server" Text="Test" />
<cc1:ModalPopExtender ID="mp1" runat="server" PopupcontrolID='pnlEdit" TargetControlID=btnTest" OkControlID="btnSubmit" CancelControlID="btnClose" BackroundCssClass="modalBackground" ></cc1:ModalPopupExtender>
<asp:Panel ID="pnlEdit" runat="server" style="display:none">
<div class="modalPopup>
<p>Text goes here.</p>
<asp:Button ID="btnSubmit" runat="sever" Text="Submit" />
<asp:Button ID="btnClose" runat="sever" Text="Close" />
</div>
</asp:Panel>
Code Behind currently has nothing for this. I have tried the same code with the variation of giving the btnTest an OnClick that does mp1.Show();. And also tried adding a "dummy" TargetControlID that is rendered but not shown in order to use the Code Behind to fire.
Every variation produces the same results. The "Test" button is clicked and then nothing happens. It appears that the page is reloaded. What am I missing here?
Please take a look at this Solution

ASP.net C#. Multiple pages in one

So I am using ASP.NET 4.5 web forms.
I have this form where I want a user to enter data, after the users enters data they should be able to press the next button and they can enter more data.
Is it possible to do this on one ASPX form, or do I need to create another ASPX form.
e.g
Username
Password
--- User clicks the next button---
Email
Phone
--- User clicks finish ---
Yes this is possible through asp.net Wizard control or MultiView control. You should be able to find these controls in ToolBox under standard category.
To learn more about these controls, please follow these links:
https://msdn.microsoft.com/en-us/library/wdb4eb30(v=vs.140).aspx
https://msdn.microsoft.com/en-us/library/ms227665(v=vs.140).aspx
Create two divs, one for username and pwd and another for email and phone.
Using jquery 'hide' and 'show' effects you can control both divs, set 'show' for when user click next button.
I am not sure whether this is a right solution for you.
Try this:
Initially, I hide the email and phone, when the user clicks next, it set the style to display:block to show the two textboxes
<script>
function showDiv() {
document.getElementById('divEmailAndPhone').setAttribute('style', 'display:block');
}
</script>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" Text="Username">
</asp:Label>
<asp:Label runat="server" Text="Password"></asp:Label>
<button onclick="showDiv(); return false;">Next</button>
</div>
<div id="divEmailAndPhone" style="display:none">
<asp:Label runat="server" Text="Email"></asp:Label>
<asp:Label runat="server" Text="Phone"></asp:Label>
</div>
</form>
you can do it in one page.
Just add two other textboxes and set visible false to them.when you press next button change the label text and set visible true to these textbox and hide username and password text box.

How can i add new panel at run time in asp.net

I am working on an asp.net web application where I have predefined panel in my project with
CSS. Now i want to create another panel with same design and CSS at run time at multiple times. I have a button control when i will click that button it will add another panel.
Please help me to add another panel with same criteria.
If it is something that you plan on reusing, I'd suggest you utilize a user control for this. You can them simply add a new instance of the control on your page.
A few things worth looking into:
https://web.archive.org/web/20210707024005/http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
http://aspalliance.com/565
http://msdn.microsoft.com/en-us/library/c0az2h86.aspx
If you wanted to accomplish this with a postback to the page, add this to your event...
//MyControl = Custom User Control
var myControl = (MyControl) Page.LoadControl("MyControl.ascx");
this.ControlContainer.Controls.Add(myControl);
Like RSolberg said, you could write a User Control and add it multiple times:
<my:UserControl id="MyControl1" runat="server" />
<my:UserControl id="MyControl2" runat="server" />
<my:UserControl id="MyControl3" runat="server" />
Of course, your User Control can be as simple or as complex as you like, thus having repeated functionality on your page.
However, depending on your exact needs you might want to consider something like an ASP.NET Repeater, or ListView, or DataGrid control. With something like a Repeater, you can bind data to it, and have that data be displayed in a list/grid, that has a common look and feel. You can give your Repeater a HTML/CSS template for the header, items, and footer sections too to make it look consistent and professional.
<asp:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<h1>Products</h1>
</HeaderTemplate>
<ItemTemplate>
<p>
Product name: <%# Eval("ProductName") %>
</p>
</ItemTemplate>
</asp:Repeater>
and in your code just do this:
MyRepeater.DataSource = products;
MyRepeater.DataBind();
There are many ways of doing what you're asking in ASP.NET - be a bit more specific and we'll be able to give you more specifc help.
Couldn't you just create a new panel in the code behind on the button's "On_Click" event? That would be my suggestion. You may need to have a placeholder to add the panel into something so it appears on the page.

ASP.NET Ajax modal popup extender within a custom user control display issues

Currently I have a custom user control and within it is a little form and a modal popup extender, the idea is for the user control to be loaded dynamically in the parent page and displayed so the user can fill out the form and submit it and all the submission code be handled on the user control
the problem I am having is when trying to make the modal popup display so the user can interact with it, nothing is being displayed at all, code follows:
the user control:
<asp:UpdatePanel ID="breakTheGlassUpdatePanel" runat="server">
<ContentTemplate>
//some fields for entry and a submit/cancel button
</ContentTemplate>
</asp:UpdatePanel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="breakModal"
TargetControlID="breakModalHolder"
BackgroundCssClass="btgModalBackground"
DropShadow="true"
PopupControlID="breakTheGlassUpdatePanel" />
<asp:Button ID="breakModalHolder" runat="server" Style="display:none;" />
Code in parent page:
BreakTheGlassControl btgControl = (BreakTheGlassControl)Page.LoadControl("~/ARISUserControls/BreakTheGlassControl.ascx");
AjaxControlToolkit.ModalPopupExtender breakModal = (AjaxControlToolkit.ModalPopupExtender)btgControl.FindControl("breakModal");
breakTheGlassPanel.Controls.Add(btgControl);//panel in parent page
breakTheGlassPanel.Visible = true;
breakTheGlassPanel.Controls.Add(btgControl);
breakModal.Show();
This page might help you. Essentially, it creates a normal panel and places the updatePanel inside it. The normal panel is then used as the Extender's PopupControlID attribute.

Categories

Resources