mardi 4 août 2015

Can't get Control with FindControl()

I am using a MasterPage site. in default.aspx code-behind, i create many container DIV (ie. each DIV is a SQL result):

HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("id", "div_" + postid);

Then create more DIV in code behind (divBottom) programatically and add it to the container DIV, with the following controls inside it:

LinkButton lnkConfirmo = new LinkButton();
lnkConfirmo.ID = "lnkConfirmo_" + postid;
lnkConfirmo.Text = "Foo";
lnkConfirmo.Click += (sender, e) => { UpdateLabel(sender, e, postid); };

Label lblConfirms = new Label();
lblConfirms.ID = "lblConfirms_" + postid;
lblConfirms.Text = "<small><a href=\"javascript:;\">" + GetConfirmTotal(postid) + " pessoas</a> confirmam.</small>";
lblConfirms.Attributes.Add("runat", "server");

And finally add the bottom div to the container.

div.Controls.Add(divBottom);

On the UpdateLabel() method, i am not being able to change Label text when LinkButton is clicked.

    public void UpdateLabel(object sender, EventArgs e, int postid)
    {
        object ctl = (this.FindControl("ContentPlaceHolder1_lblConfirms_" + postid.ToString()) as Label);
        HtmlGenericControl ctl2 = (HtmlGenericControl)this.FindControl("ctl00").FindControl("ContentPlaceHolder1").FindControl("lblConfirms_" + postid);
        //I tried more combinations of this.
    }

I tried Label and HtmlGenericControl because Label is rendering as a span. How can i access that span to change its text, or make this an available control to be accessed? Some controls are available on this.Page.Form (such as some divs, ContentPlaceHolder, ScriptManager and many "Literal), but not the Label as it isn't being rendered as a Control, i guess.

This is the Html output:

<div id="divConfirms_24"><span id="ContentPlaceHolder1_lblConfirms_24" runat="server"><small><a href="javascript:;">190 users</a> confirmam.</small></span></div>



via Chebli Mohamed

Changing ASP.Net label's text with VB.Net

I currently have a form that has a label appear when there is an error with changing your password.

Currently there is a bug that makes a message pop up even when the change is successful that says, "Object reference not set to an instance of an object."

I'm wanting to write a test that says when the label is equal to that message to make the visibility false. I've tried:

If lblMsg.Text = "Object reference not set to an instance of an object." Then
            lblMsg.Visible = False
        End If

This, among other variations, have yet to work successfully for me.

Any idea on what other ways I can write this out to hide the label when that message occurs?



via Chebli Mohamed

How to setup a local wayback machine like that of Internet Archive?

I depend on our Government website for my research. There are some sites in those on which content and links appear and vanish on everyday basis. Their sites are terribly designed and they willfully take down some links or bury some things deep inside to make it hard for any one to find. The problem is I need to refer to something that was on the website months or years ago. Most of the time, I end up not finding it.

Is there a way to locally archive the sites and browse them like we do on wayback machine?



via Chebli Mohamed

How can I navigate to a different URL when user clicks the hyperlink in the GridView with a condition?

I am a beginner in learning asp.net. I have a column in a GridView with header name FORM ID. I want to be able to navigate to the different URL based on the part of the FORM ID.

For example,

  • Clicking on abc10001 will take us to "~/abc1.aspx?formid=abc10001"
  • Clicking on abc20001 will take us to "~/abc2.aspx?formid=abc20001"

I understand the use of the MID function like so v=MID(string,4,1) to capture the 4th value and redirect to page by determining the value v but I do not know how to apply this correctly. Please guide me. Your help is greatly appreciated.

The following is the aspx code I'm currently work on :

<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">           
    <columns>
        <asp:Hyperlinkfield DataTextField="formid" HeaderText="Form ID" ItemStyle-  Width="150px" 
            DataNavigateUrlFields="formid" DataNavigateUrlFormatString="~/abc1.aspx" />         
    </Columns>
</asp:GridView>



via Chebli Mohamed

ASP MVC 5 Web Application not Rendering CSS. Deployed Via Web Deploy

I deployed a MVC 5 Application via web deploy to IIS 8. It is not rendering my bootstrap.css. I'm not sure where to begin from a troubleshooting perspective as this is my first MVC 5 Deployment.

I attached my web config below

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="JCI.MW.WebFrontEnd" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>

  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>



via Chebli Mohamed

Why is localization not working for gridvew?

Why is my localization not working with gridview ?

I have made resx files:

BoundFieldLCode.HeaderText      کد زبان 
BoundFieldText.HeaderText           متن 

and bound fields:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID">
        <Columns>
            <asp:BoundField DataField="Text" HeaderText="Text" meta:resourceKey="BoundFieldText" />
            <asp:BoundField DataField="Language" HeaderText="Language Code" meta:resourceKey="BoundFieldLCode" />
        </Columns>
    </asp:GridView>

and put this in header of page directive

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Report.aspx.cs" Inherits="_Default"  Culture="auto:en-US" UICulture="auto" %>



via Chebli Mohamed

What is the default TokenLifespan of GeneratePasswordResetTokenAsync and GenerateUserTokenAsync

I have looked everywhere and cannot seem to find out for sure what the default for each of these is.

I also need to know if there is a way to set different Lifespans for each. Thanks,



via Chebli Mohamed