Jump to content
Xtreme .Net Talk

GregD

Members
  • Posts

    15
  • Joined

  • Last visited

GregD's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hi, I have 2 user controls each of which has a seperate datagrid. Im trying to get it so from each .vb file for each control i can disable both datagrid EditItemIndex using EditItemIndex = -1 So i have usercontrol1.vb and usercontrol2.vb The problem im having is I can't reference the usercontrol2 datagrid from usercontrol1. E.g. in usercontrol1.vb usercontrol1.EditItemIndex = -1 usercontrol2.EditItemIndex = -1 This wont work because usercontrol2 datagrid is not referenced in usercontrol1.vb Someone suggested raising an event at the page_load in a page.vb file but ive had little success.. Any suggestions?
  2. I have included an iframe in my datagrid and im trying to put <%# Container.DataItem("article").Trim()%> into the iframe like a wysiwyg editor. The datagrid is in a usercontrol. Ive tried: iView.document.write('<%# Container.DataItem("article").Trim()%>') iView.document.close() In my aspx where iView is the ID of my iframe... but i just get 'DataItem' is not a member of 'System.Web.UI.Control'. Ive tried putting the javascript in the user control but no luck there either. Anyone been able to do this? Thanks
  3. Worked it out but damm was not easy at all... Sub WalkControls(ByVal parent As Control, ByVal level As Integer) Dim ctrl As Control For Each ctrl In parent.Controls If ctrl.GetType().BaseType.Tostring = "CMS.ModSecDesc" Response.Write("<b> " & ctrl.ID & "</b> " & ctrl.GetType().FullName & "<br>") End If ' **** Recurse into this item's Controls collection if it's not empty If ctrl.Controls.Count > 0 Then WalkControls(ctrl, level + 1) End If And in Page_Load: WalkControls(Page, 1) Found it here and adapted it a bit using basetype: http://www.dotnet247.com/247reference/msgs/5/29593.aspx
  4. I tried using the following code which I found on http://aspnet.4guysfromrolla.com/articles/082102-1.aspx void IterateThroughChildren(Control parent) { foreach (Control c in parent.Controls) { if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") && c.ID == null) { // ...do something... } if (c.Controls.Count > 0) { IterateThroughChildren(c); } } } But it only iterates through the child controls not the parents i.e. my custom user controls. I tried using the user control class instead of just the control class but it doesn't work. Any ideas? Im trying to get all the IDs for the control type ModSecDesc: <CMS:ModSecDesc id="blah" runat="server"/> <CMS:ModSecDesc id="moo" runat="server"/>
  5. Thanks! Yep quite right... How would I find all the user control ID's on a page for the class ModSecDesc ? i.e. Ctype(Me.FindControl("*"),ModSecDesc) Obviously it wouldnt be * but i need to get all the ids without actually knowing them if you see what i mean. I had a look at the page class but could only find Page.ClientID which only works if you know the ID. Thanks
  6. How can I grab the tag names of all the user controls currently loaded on a page... the tag names are specified by the @Register command at the top of the page like so: <%@ Register TagPrefix="CMS" TagName="LoginControl" Src="login.ascx" %> <%@ Register TagPrefix="CMS" TagName="ModSecDesc" Src="secdesc.ascx" %> So for this page I want to get LoginControl and ModSecDesc into 2 different variables. Im pretty sure its the system.web.ui.UserControlControlBuilder class that I should get the property from but how do I do it? Thanks!
  7. Hi guys thanks for your recomendations.. I managed to fix it. Turns out I needed to compile all my VB files and reference it in the user control as: <%@ Control Language="VB" inherits="CMS.ModSectionDesc"%> Apparently it didnt work the other way (just referencing the file) because it was trying to call page_load when there already was one in my other VB file CMS.Login So i had compiled CMS.Login but i was pointing directly at the file for CMS.ModSectionDesc and thus .NET seemed to get confused and used the page_load from Logins rather than the other one.
  8. Thanks but I have already read this tutorial series parts 1-16 and there is absolutely nothing concerning implementing the datagrid into your own ASCX file with a codebehind.
  9. Hi, Ive tried to put my datagrid in a usercontrol/codebehind file but it just doesnt seem to work. It worked fine in a standard aspx file but putting it into a codebehind seems more complicated. Any good tutorials in VB on this? This is where im at, there are no errors on the code but the Datagrid doesnt even show up. I know that the aspx and ascx pages are linked properlly because if i put in some errors on purpose ASP.NET reports them. secdesc.ascx: <%@ Control Language="VB" SRC="bll/secdesc.vb"%> <asp:datagrid ShowHeader="False" GridLines="None" id="index_sections" runat="server" EnableViewState="true" AutoGenerateColumns="false"> <columns> <asp:templatecolumn> <itemTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr valign="top"> <td width="50" align="top"> <img src="<%# container.dataitem( "image") %>" align="top"></td> <td ><a href="<%# container.dataitem( "titleLink")%>"> <%# container.dataitem( "title")%> </a> <br> <%# container.dataitem( "article") %> </td> </tr> </table> </itemtemplate> </asp:templatecolumn> </columns> </asp:datagrid> codebehind secdesc.vb: Imports System Imports System.Configuration Imports System.DateTime Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Imports System.DBNull Imports System.Web Imports System.Web.Security Imports System.Web.SessionState Imports System.Web.HttpServerUtility Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.Datagrid Imports System.Web.UI.HtmlControls namespace CMS Public Class ModSectionDesc Inherits System.Web.UI.UserControl '====================== 'Web controls '====================== Protected WithEvents index_sections As System.Web.UI.WebControls.Datagrid '====================== 'Propertys (set/get) '====================== '====================== 'Subroutines '====================== Public Sub Page_Load(ByVal sender as System.Object,ByVal e as System.EventArgs) BindData() End Sub Public Sub BindData() dim isSecure as String 'checks if the site uses http:// or https:// so we can build up our where condition in the SQL Stored Procedure If Request.ServerVariables("HTTPS") = "off" Then isSecure = "http://" Else isSecure = "https://" End if 'SQL Stored Proc to get the modules for this appropriate site/page. Dim conn as New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionString")) 'Create new command object and query the database. Open the connection. Dim myCommand As SqlCommand = New SqlCommand("sp_getmoddesc", conn) myCommand.CommandType = CommandType.StoredProcedure conn.open() 'Set up parameter for stored procedure Dim prmRootPath As New SqlParameter() Dim prmPagePath As New SqlParameter() 'parameters prmRootPath.ParameterName = "@rootpath" prmPagePath.ParameterName = "@pagepath" prmRootPath.Value = isSecure & Request.ServerVariables("HTTP_HOST") prmPagePath.Value = Request.ServerVariables("PATH_INFO") 'add the parameter to the command myCommand.Parameters.Add(prmRootPath) myCommand.Parameters.Add(prmPagePath) index_sections.DataSource = myCommand.ExecuteReader() index_sections.DataBind conn.close() End Sub End Class End namespace Any help would be great thanks!
  10. Ok call me silly here but i've never done this before, im currently making a portal/CMS. Ive done plenty of database selects inserts etc etc for ages, now ive come to the point in this new project where ive just realised something crucial... how on earth do i get the content in/out of the database as html? I assume I have a textbox server control and insert the text in the database that the user has edited but how do i format it as html so rather than: Hello! It's: <b>hello</b> or whatever! I want it to act like a normal text box but have say a bold button which makes selected text bold and can write that with <b> tags into a DB. Please someone enlighten me ive been searching forums and my .net books this evening but havent found anything!
  11. Im currently working on a portal so I need to always have the current login state displayed because you can login on any page. Another great thing to check out is smart navigation. Try inserting it into your page directive: <%@ Page Language="VB" SmartNavigation = "true"%> From the documentation: "Smart navigation is an ASP.NET feature that is supported in Internet Explorer 5.5 and later browsers. It allows a page to be refreshed while maintaining scroll position and element focus between navigations, causing only a single page to be stored in the browser's history, and without the common flicker associated with refreshing a Web page. Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this attribute to true." This seems like a cool feature shame its only for IE :)
  12. Solved this myself after reading up on cacheing and user controls. For anyone interested: Created a new user control and put the following in the page_load of it... Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.Cache.SetExpires (DateTime.UtcNow) Response.Cache.SetNoStore() Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches) So basically only the user control is being reloaded rather than the whole page. Thanks for your suggestion anyway.
  13. Ive seen it done in PHP.... over at forums.aspfree.com (no advertising intended) ;) Even when I press back it realises im logged in. I know this is .NET but come on .NET can do tons more than php surely :)
  14. Hi, On every page on my site i plan on having a username/password textbox and a submit button. Once the user has logged in im hiding these controls and replacing them with a logout button. Im doing all this with the .visible method. This works to a point but lets say ive browsed the website and ive decided to login after the third page. If i press the back button i have to refresh the page before the controls become invisible. Is there a way of making the page not cache certain user controls ? Could i give them their new invisible status with viewstate or postback maybe? So far ive only found Response.CacheControl = "no-cache" But then users need to refresh the whole page. Any suggestions would be appreciated.
×
×
  • Create New...