I have an ajax container which will be created dynamically in C#. I would like the container width to be set to 100%. Have researched online for quite awhile but still can't figure out how to set the width to 100%.
This is my codes:
//Aspx file
<div>
<asp:scriptmanager ID="ScriptManager1" runat="server">
</asp:scriptmanager>
</div>
<asp:updatepanel ID="UpdatePanel1" runat="server" ScrollBars="Horizontal">
<contenttemplate>
<asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
<asp:Chart runat="server">
</asp:Chart>
</contenttemplate>
</asp:updatepanel>
//Cs file
AjaxControlToolkit.TabContainer container = new AjaxControlToolkit.TabContainer();
container.ID = "TabContainer";
container.EnableViewState = false;
container.Tabs.Clear();
container.Height = Unit.Pixel(2000);
container.Width = Unit.Pixel(2000);
container.Tabs.AddAt(0, GetManualTab());
Question: How to set Ajax tab container width to 100% if the container is created dynamically in c#?
Appreciate if anyone provide me help on this. Thanks a lot!!
container.Width = Unit.Percentage(100);
Related
I have below structure in my asp.net application.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="overlay"></div>
<asp:Panel ID="pnlMain" runat="server" Visible="true">
<asp:UpdatePanel ID="upProfile" runat="server" UpdateMode="Always">
<ContentTemplate>
<div>
<table>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upAttachment" runat="server" UpdateMode="Always">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlSuccessMessage" runat="server" >
<asp:Label ID="lblSuccessMessage" runat="server"></asp:Label>
</asp:Panel>
I have different textfields and dropdowns in the table of upProfile updatepanel and file upload control in upAttachment updatepanel. Now when I select one radio from the same update panel, I am getting below error and the upAttachment does not show up on page.
Uncaught Error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'MainContent_upAttachment'. If it is being updated dynamically then it must be inside another UpdatePanel.
I have searched a lot and tried below different things, but still it is not working
1. Set the upAttachment UpdateMode to Conditional.
- In this case, it does not throw error, but the file upload control which is inside that updatepanel, it does not show up
2. Place the upAttachment updatepanel inside another updatepanel, but that too is not working.
I don't know what to do in this case. Can anyone help me on this?
for example i have this code in ex1.aspx :
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- CODE1: some gridview or other asp elements here -->
</ContentTemplate>
</asp:updatepanel>
</form>
and i have this code in other page ex2.aspx
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- injection CODE1 to here in run time -->
</ContentTemplate>
</asp:updatepanel>
</form>
how can i get the CODE1 inside the ex2.aspx updatepanel in run time ?
for example when i click on some asp:button "clickToLoadGridView"
edit:
i tried already:
- user control ascx - but the problame is that there is conflict with form runat server. for example if i load a gridview with connection to database it will not work. i guess he lose the connection when he return from server.
the code i tried to load a gridview ascx is:
using (Page objPage = new Page())
{
UserControl uControl = (UserControl)objPage.LoadControl("GridView.ascx");
objPage.Controls.Add(uControl);
using (StringWriter sWriter = new StringWriter())
{
HttpContext.Current.Server.Execute(objPage, sWriter, false);
return sWriter.ToString();
}
}
after it returned i append with jquery the code to the html.
then i can see only the first page of the gridview . but when if the grid view is paging and i click on the second button page i get page "This webpage is not available" .
I have a webpage that is just a bunch of gridviews on the page, they display data pulled from a SQL database (using Stored procedures). I have the whole page using a javascript defined refresh function, and it works great (timer is set for every 10 mins).
I have one Gridview that I want to refresh every 15 seconds (they want that data to be the most current always). I have tried 3 different ways to get this functionality, but each has the same side effect. Instead of refreshing that specific gridview, it makes another gridview at the top of the page with the data. I'm not sure what I'm missing here, so any help would be appreciated.
Below is the code for the grid view I'm having issues with, if you need more code, please let me know.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="PDUpdatePanel" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="15000">
</asp:Timer>
<td valign="top">
<asp:GridView ID="PD" AutoGenerateColumns="true" runat="server">
</asp:GridView>
</td>
</ContentTemplate>
</asp:UpdatePanel>
EDIT
I have tried the above (using the script Manager/UpdatePanel/Trigger), I have tried using this (using the Timer1_Tick to call to rebind)
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="PDUpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="15000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Panel runat="server">
<td valign="top">
<asp:GridView ID="PD" AutoGenerateColumns="true" runat="server">
</asp:GridView></asp:Panel>
</td>
</ContentTemplate>
</asp:UpdatePanel>
When this I tried the simple, just call the SP and rebind
protected void Timer1_Tick(object sender, EventArgs e)
{
DataAccess.PDGet(GridView PD);
}
public static void PDGet(GridView PD)
{
//Create connection
using (AdoConnNet conn = new AdoConnNet(Config.GetConfigKeys("AppName"), Config.GetConfigKeys("LogPath")))
{
conn.SetConnection(Config.GetConfigKeys("SERV_CONVEYOR"), "Conveyor");
string spTimeOutCountGet = Config.GetConfigKeys("TimeOutCountGet");
using (SqlCommand cmd = new SqlCommand())
{
//Call SP and load the results
using (SqlDataReader dr = conn.RunSPReturnDataReader(spTimeOutCountGet, cmd))
{
PD.DataSource = dr;
PD.DataBind();
}
}
}
}
Lastly, I tried making a helper function one that get the data from the Database, and another to do the binding (grasping at straws at this point).
The side effect is the same with every way I tried. Instead of refreshing the GridView PD in it's current location, it makes a new Gridview at the top of the page (and pushing the rest of the gridviews down). I'm not savvy with Web pages, so I'm unsure why it's drawing it at the top instead it's current location.
Thanks for the help!
All I wish to do is simply click a button and the text in a textbox is automatically added as an item in the listbox. Shouldn't this be straight forward? Whilst debugging, the item is added and I can see the text by watching ListBox1.Items[0], but nothing is displayed in the web page. I had the same problem which i did not solve, in a console application! Can some one please guide me to what I am doing wrong?
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(TextBox1.Text));
}
Many thanks
Edit:
In a past project, I used the DataSource property, which worked perfectly. I have never yet managed to use the add Items! May be there is some sort of refresh or update?
Page code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="295px"></asp:ListBox>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Looks like your listbox is outside of the update panel. Pop it inside the update panel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="AddItem" />
</ContentTemplate>
</asp:UpdatePanel>
You have to move the ListBox into the UpdatePanel, otherwise it will not be updated.
The reason for that is, that ASP.NET is sending the whole HTML of the UpdatePanel back to the client. Since the ListBox is not part of the UpdatePanel, it won't be updated.
I'm having trouble with a combination of an UpdatePanel and MultiView.
I have an UpdatePanel at my top level, inside I have a bunch of imagebuttons - their click events set the view on the Multiview, and each View has an UpdatePanel inside of it with my binding.
Everything works great - but I am trying to set the View via the Querystring, so I can send a user to a particular view.
When I try and set the View from PageLoad - it says 'object does not exist'. So I figured I'd try it in Page_LoadComplete, which works great - but then my imagebuttons don't work to switch the view like they originally did.
What am I missing! Thanks!
void Page_LoadComplete()
{
tabSelect= Request.QueryString["tab"];
if (tabSelect.Contains("Community"))
{
MultiView1.SetActiveView(Community);
btnCommunity.ImageUrl = "images/tabCommunity_on.png";
}
}
<asp:ScriptManager id="ScriptManager1" runat="server"/>
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
<ContentTemplate>
<asp:ImageButton id="btnCommunity" onclick="" runat="server">
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="Community" runat="server">
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
<asp:View id="tabFriends" runat="server">
<asp:UpdatePanel id="UpdatePanel2" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
UPDATE: After reviewing your code in further detail, I believe figured out the problem.
I made the following adjustments to the code:
If the querystring is not passed, set tabSelect to empty string and thus avoiding a null object reference exception on the next line.
Set the ImageUrl path to include ~ (for root).
Please try the code below:
void Page_LoadComplete()
{
string tabSelect = Request.QueryString["tab"] ?? string.Empty;
if (tabSelect.Contains("Community"))
{
MultiView1.SetActiveView(Community);
btnCommunity.ImageUrl = "~/images/tabCommunity_on.png";
}
}