.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Changing a control attribute at runtime.

Posted By:      Posted Date: October 20, 2010    Points: 0   Category :ASP.Net

Hi Guys,

I'm basically trying to get a div containing a loading gif to show on my page at runtime. I call it from a button click event as well as in the code flow. It was working before I used the AJAX Update Panels. I've since taken them out as they were causing issues with RegisterClientScriptBlock. By the way, does commenting out the AJAX Markup like this...

<%--           <asp:UpdatePanel ID="up_search" runat="server">

...remove them from influence?
My div markup looks like this..
<div id="loading" style="visibility: hidden;" runat="server">
    <img id="loading_gif" alt="Loading..." class="loading" src="Images/panel_loading.gif" />

My code is initiated from the button click event.

    protected void btnSearch_Click(object sender, EventArgs e)

        //show the loading image

View Complete Post

More Related Resource Links

Category attribute of user control property does not work correctly in categories tab.



I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".

[Category("Styles"), DefaultValue(""), Description("The value for formating something.")]
public String MyFormatProperty
set { /* the code for set */; }
get { /* the code for get */; }

And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.

Does anybody know why? How can I display the category correctly only with set?

Thanks, S.

Programmatically Changing the Profile Provider at Runtime


Dear All

I'm using one application but have multiple providers in my web.config for memberships, roles and profiles to allow my application to be used by different groups of users who need to connect to different databases.

This means I'm having to change the membership, role and profile providers on-the-fly in my code-behind files. So far I've taken care of the membership and roles a bit like this:

Dim RolePV As RoleProvider = Roles.Providers(GetSettingFromFile("Provider"))

However, I'm having trouble finding out how to do the same sort of thing for Profiles. I've looked at ProfileProvider and ProfileManager but I can't work it out how to access my the profile property that I've created in my web.config file called "ScreenSize". Normally you would just write Profile.ScreenSize to read or write to the property.

Please can you help me to understand how I access the profile property called ScreenSize by dynamically setting the profile provider first?

I'd be very grateful for any help or advice.

Many thanks



changing records frm control in update panel


i have a list box, a command button and a grid

when i click a particular record / or multiple records on the  list box and then cclick the command button the records r transferred 2 the grid

i also have custom paging, the paging shld ocur as many times i clcik the command button

i have used updatepanel with the command button in it so that partial postback ocurs or there is no page flicker ,

but when i use update panel i get teh records in the grid but custom page is not working . it has no affect even if the records are added

if i remove update panel the paging works properly

how do i manage it with update panel

cannot set name attribute value when using a container control

Hi,I created a usercontrol with a Grid. <UserControl x:Class="TestUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300"> <Grid Name="MainGrid" Background="Red" > </Grid> </UserControl> Next I created another Project and referenced the dll where this usercontrol is in. <UserControl x:Class="TestContainer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:nds="http://schemas.test.eu/BaseElements" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300"> <Grid> <nds:TestUserControl> <Button Name="Btn1"></Button> </nds:TestUserControl> </Grid> </UserControl> With the schema i can load a instance of this usercontrol onto the new usercontrolNext I load a button onto thisWhen I now set the name property, the error "Warning 1 Cannot set Name attribute value 'Btn1' on element 'Button'. 'Button' is under the scope of element 'TestUserControl', which already had a name registered when it was defined in another scope. Line 7 Position 21. ......

Problems with a .NET4 Control GAC Reference failing at runtime but fine during debugging

I believe this question is specific to the CLR how ever I will test this in a Forms Application later. I have multiple .Net 4 Targeted WPF Applications that Reference Non Microsoft .NET 4 WPF Controls that I can confirm are in the GAC. Everything Debugs Great (Noting that none of the references are copied to the output directory) and Install's well using a Setup Package and manually installing has the same effect even after a reboot. The problem is the application will not start even as an administrator as it does not find the Control References in the GAC. This also happens if I try to start the application manually in the visual studio output Directory. I can also confirm that opening the application in reflector that reflector is able to correctly find the references. Finally if I copy the controls (.dll's) to the location of the application everything runs as expected for all the above issues.   My question here is why is my application not able to load the .NET 4 controls from the GAC? Also note that everything uses a Strong Name.

Changing title o sitemapnode at runtime from code behind c#

Hi guys ! I have a site map on my project and I have section which get values from sql database and it changes according to querystring Id value. In my sitemap the title of the page is everytime same. but I want tpo change it at runtime. I am using multiple sitemaps and My sitemap is not the default one. its name is rootSitemap. I tried some code which I got from msdn but it seems doesn't work for me; protected void Page_Load(object sender, EventArgs e) { SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ExpandForumPaths); } private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e) { // The current node represents a Post page in a bulletin board forum. // Clone the current node and all of its relevant parents. This // returns a site map node that a developer can then // walk, modifying each node.Url property in turn. // Since the cloned nodes are separate from the underlying // site navigation structure, the fixups that are made do not // effect the overall site navigation structure. SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true); SiteMapNode tempNode = currentNode; tempNode.Url = tempNode.Url + "?TransferType=" + Request.QueryString[0].ToString(); tempNode.Title = "My Transfer Desc - " + Request

changing the content of website runtime

say i have a table in my website that contain <tr>  and <td> and "hello good morning" is wriiten over there. how can change the content of my website to "hello good night" on a click of button or using any other way of doing  this like yahoo and other popular website did.

Calling a method on a Web User Control that is added ar runtime


Greetings All!


I have a Web Form that uses Master Pages. I only tell you this part so you understand the layers.


On the page, I have a web user control.  I can see public methods on that user control by simply calling  userControlName.PublicMethod();


However, there is a button on this page which generates additional content.  This content is based on a placeholder control and adding additional web user controls :


private void buildSubForms()
            Control subForm;
            // load in the Lesson Topic Sub Form
            subForm = LoadControl("~/siteAssets/controls/ilasLT.ascx");
            // load in the Reference Material Sub Form
            subForm = LoadControl("~/siteAssets/controls/ilasRM.ascx");


Now, on the main form, I want a submit button that will call a public method of each "subForm" that was added at runtime.


I have tried  various forms of Control C = This.Page.Master.FindControl("cpBody").Findcontrol("ctl01")... etc, but can never seen to get the right combination.

I am sure more info

Change search scope for SharePoint search control at runtime

I have a requirement where based on a users SharePoint group, there search should be for a specific scope. My question is, is it even possible to change the SharePoint search box to use search a particular scope at runtime?

Setting DestinationPageURL in runtime for login control



I have a master page which has login view control for login. I display the same login control for two different internal pages login. I want to set destination page url in the run time immediately after user is authenticated something like below.

 if (MyUrl.AbsolutePath.ToUpper() == "url1")

                login.DestinationPageUrl = "destinationurl1";
                login.DestinationPageUrl = "destinationurl2";

but i am getting error "Object reference not set to an instance of an object." for the login control when i tried using the above code in loginbutton click event.

Please let me know where i can implement this code or is there any other easy way to implement this. I am using sql membership roles and users to login. Same user can have both the roles so that i am verifying the url instead of checking the user in role to navigate.

Thanks in advance.

changing the control position


How can i change control position in aspx page at runtime Is it possible through xml / xslt  files
with out re-depoying the code.Any sample code / links
Please help me out 

DataBinding not updating underlying business object when changing control property from code


I have a custom data form control that in code generates databindings between the selected custom business object (LLBL) and the various controls on the screen. Everything works in that I set the DataContext to the selected business object and the data appears in the GUI. If the user changes anything on screen, the data is getting updated into the business object.

However, now I have some custom logic that when the user presses a button I need to update some fields. Currently I'm setting this data directly into the controls, setting the new value into the property that is bound. However, the data is not getting pushed back into the business object.  I had this same issue building WinForm apps in that databinding only fired if the user was in the control and left it.

Does the same thing apply to WPF? How can I get ANY change on say a TextBox's Text property whether via user interaction or from C# code to push that value into the bound business object property?


Changing the address in app.config at runtime ..AN ISSUE..HELP neede..

hi wcf champs.,

hmm...I have a problem..and seriously need a solution to get things done well..!!

Have developed a wcf Upload application,the wcf service is hosted on IIS..now,the endpoint address at the server is exposed at client(in app.config).If further the server ip changes to some other..then the address at the client must be changed..!right..ya I did something to handle this but ,its another problem..!!.

Let me say what i have done and why does that give a problem..


*.*.The server ip is stored in a xml file.When the application runs,it picks up the server ip and changes it in Client.exe.config...

*.And if there is EndpointotFound exception at the client,it asks the admin to check the ip of the server.

*.The admin checks it and if the server ip is changed,the admin changes the ip in the xml file (where server ip is stored).

now let me know.."IS THIS A RIGHT APPROACH TO SOLVE MY PROBLEM" ..But then there is a problem!!let me share that with u..


*.The ip that is picked from  xml and placed in Client.exe.config.

Changing crid cell content at runtime


In a cell in a grid, I have a TreeView. When the parsing of the data behind the treeview yields an error, I would like to replace the treeview with a textblock with information on the error details.

I'm thinking about using a datatemplateselector, but I can't figure out how, or if this is the best approach. Any suggestions?

Alternatively I will place a ContentControl in the grid cell and populate it with the correct content from the code behind file, I just think there could be a more elegant solution in pure XAML.

dynamic javascript of an .ascx control inside an updatepanel not changing on client between async po


I have a confusing state issue. I found a way around it, but I would like to know why this is happening. First of all, I am using .NET 3.5 and that can't change right now (an easy fix may be the fixed ID capabilities of .NET 4.0).

Type csType = this.GetType();
ClientScriptManager cs = Page.ClientScript;
string jScriptBlockName = "SignUpSignInNameAvailabilityScript";
if (!cs.IsClientScriptBlockRegistered(csType, jScriptBlockName))
{   //NOTE: verified code always enters this
    StringBuilder cstext2 = new StringBuilder();
    cstext2.Append("function GetSignUpSignInNameAvailabilityMessage() { var id = '"
          + CreateUserWizardStep1.ContentTemplateContainer.FindControl("iSignUpSignInNameAvailabilityMessage").ClientID
          + "'; alert(id); return id; }");
    cs.RegisterClientScriptBlock(csType, jScriptBlockName, cstext2.ToString(), true);

This code is in Page_Load of an ascx. The same control is drawn on two separate postbacks of an UpdatePanel in different places of the page thus giving them different client IDs. The code works correctly on the first refresh of web browser; but after UpdatePanel

UpdatePanel Reference in control.ascx.designer.cs keeps changing


I have an annoying problem when I'm developing in Visual Studio 2010. I am using an UpdatePanel in my .ascx file like this:

<asp:updatepanel id="upStuff" runat="server">....</asp:updatepanel>

in my control.ascx.designer.cs, the update panel is being defined like this:

protected global::System.Web.UI.WebControls.WebParts.updatepanel upSettings;

this produces the error:

"The type or namespace name 'updatepanel' does not exist in the namespace 'System.Web.UI.WebControls.WebParts' (are you missing an assembly reference?)"

The actual namespace should be System.Web.UI.UpdatePanel. When I go directly into the designer.cs file and change it, it works. However, every time I go back into editing control.ascx and save, Visual Studio always changes it back to System.Web.UI.WebControls.Webparts.updatepanel.

I'm not sure what is causing this. Is it how I should be referencing namespaces and classes in my project? I'm using .NET 3.5. Any help would be greatly appreciated.

Dynamically Changing ImageUrl in HyperLink control


Hey guys,

C#/.net newb alert. ;)

I'm writing a script and need help with being able to modify the ImageUrl property in a HyperLink control from the code behind page. It is meant to dynamically show an image.

I just need to know the correct format of the code behind to get this to work.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend