asp.net

disable remove viewstate aspx

Problem:
Annoying LONG viewstate

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEyMjcx
NDEzNzQPZBYCZg9kFgQCAQ9kFgICAg8VAh4vV29ybGRHcmFubnkvanMvZGRhY2NvcmRpb24u
anMkL1dvcmxkR3Jhbm55L2pzL2pxdWVyeS0xLjIuMi5wYWNrLmpzZAIDD2QWBAIDDxYCHgtfIUl0
ZW1Db3VudAIKFhRmD2QWBAIBDw8WAh4LTmF2aWdhdGVVcmwFFH4vUGFnaW5hLzIvaG9tZS5h
c3B4ZBYCZg8VAQRIb21lZAIDDxYCHwACARYCAgEPZBYCAgEPDxYCHwEFFX4vUGFnaW5hLzQvc3V
iLTEuYXNweGQWAmYPFQEFc3ViIDFkAgEPZBYEAgEPDxYCHwEFG34vUGFnaW5hLzMvb3JnYW5pc2F0a
WUuYXNweGQWAmYPFQELT3JnYW5pc2F0aWVkAgMPFgIfAAICFgQCAQ9kFgICAQ8PFgIfAQUUfi9QYWdpb
mEvNS9zdWIyLmFzcHhkFgJmDxUBBHN1YjJkAgIPZBYCAgEPDxYCHwEFGH4vUGFnaW5hLzgvbmV3LXBhZ2" />

LOL.. long huh :D

Solution:
put this code in your .cs page

//overwrite the  SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium
protected override void SavePageStateToPersistenceMedium(object viewState)
    {

    }

    protected override object LoadPageStateFromPersistenceMedium()
    {

        return null;

    }


// Remove completely after rendering html code
 protected override void Render(HtmlTextWriter output)
    {

        System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

        System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder);

        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

        foreach (Control ctrl in this.Controls)

            ctrl.RenderControl(htmlWriter);

        String html = stringBuilder.Replace("/>", ">").ToString();

        int intViewStart = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");

        int intViewFinish = html.IndexOf(">", intViewStart) + 1;

        string strViewTag = html.Substring(intViewStart, intViewFinish – intViewStart);

        System.Diagnostics.Debug.WriteLine(strViewTag);

        html = html.Replace(strViewTag, "");

        output.Write(html);

    }

and WALA! its gone!!

find value in repeater asp net

Problem:
find value in repeater

Solution:
write this code in itemdatabound on your repeater:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label title = e.Item.FindControl("Label1") as Label; // depend on what component you r searching for


          Response.Write(title.Text);   // just check          
        }
    }

Fixing the problems in url rewriting asp.net

postbacks while using URLRewriter.net

solution:
put this code:
<%@ Register TagPrefix="url" Namespace="Intelligencia.UrlRewriter"
Assembly="Intelligencia.UrlRewriter" %>

and
change <form id="form1" runat="server"> to <url:form runat="server">

problem with Google BOT

solution:
add this code in your  App_Browsers/genericmozilla5.browser

<browsers>
  <browser id="GenericMozilla5" parentID="Mozilla">
    <identification>
      <userAgent match="Mozilla/5\.(?'minor'\d+).*[C|c]ompatible; ?(?'browser'.+); ?\+?(http://.+)\)" /></identification>
    <capabilities>
      <capability name="majorversion" value="5" />
      <capability name="minorversion" value="${minor}"/>
      <capability name="browser" value="${browser}" />
      <capability name="Version" value="5.${minor}" />
      <capability name="activexcontrols" value="true" />
      <capability name="backgroundsounds" value="true" />
      <capability name="cookies" value="true" />
      <capability name="css1" value="true" />
      <capability name="css2" value="true" />
      <capability name="ecmascriptversion" value="1.2" />
      <capability name="frames" value="true" />
      <capability name="javaapplets" value="true" />
      <capability name="javascript" value="true" />
      <capability name="jscriptversion" value="5.0" />
      <capability name="supportsCallback" value="true" />
      <capability name="supportsFileUpload" value="true" />
      <capability name="supportsMultilineTextBoxDisplay" value="true" />
      <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
      <capability name="supportsVCard" value="true" />
      <capability name="supportsXmlHttp" value="true" />
      <capability name="tables" value="true" />
      <capability name="vbscript" value="true" />
      <capability name="w3cdomversion" value="1.0" />
      <capability name="xml" value="true" />
      <capability name="tagwriter" value="System.Web.UI.HtmlTextWriter" />
    </capabilities>
  </browser>
</browsers>

Simple url rewriting ASP net with URLRewriter.Net

URL Rewriting with URLRewriter.Net

URL Rewriting has lots of benefits, listing its main benefits

  • SEO Friendly URL
  • Secured URL
  • No need to change bookmark with change in site structure.

Before URL Rewriting my URL looks like
http://localhost:2661/URLRewrite2/DynamicPage.aspx?MyTitleId=1

After URL Rewriting URL is changed to

http://localhost:2661/URLRewrite2/Article/Asp-Net-website-paths-1.aspx

Step-by-Step Explanation

Step 1: Download Binary Files for URLRewriter.Net

Step 2: Add Reference to Binary Files, Right click project "Add Reference" and add binary files.

Step 3: Update Web.Config File to make URLRewriter.Net works.

<configuration>
<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<rewriter>
<rewrite url="~/Article/(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2"/>
</rewriter>
</configuration>

Step 4: Adding Function to Generate SEO Friendly URL from given Title

public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();
#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");
//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");
//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
strTitle = strTitle.Replace(strChar, string.Empty);
}
}
//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");
//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");
//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion
//Append ID at the end of SEO Friendly URL
strTitle = "~/Article/" + strTitle + "-" + strId + ".aspx";
return strTitle;
}

Step 5: Changing DataBinder.Eval Function in .Aspx Page to reflect changes in URL of Grid.
Note: Learn more about DataBinder.Eval Function

<%#GenerateURL(DataBinder.Eval(Container.DataItem,"Title"),DataBinder.Eval(Container.DataItem,"Id"))%>

Sources :

  1. http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html
  2. http://en.wikipedia.org/wiki/Regular_expression
  3. http://urlrewriter.net/index.php/support/configuration

YAF forum multiple boards stand alone

Problem:
you want 2 diffrent forum with 1 login

Solution:
YAF is just a control so call it using the boardid as a parameter. For
instance, if you look at the default.aspx it has code that looks like
this:

<form runat="server" enctype="multipart/form-data">
<yaf:forum runat="server"/>
</form>

Now
go into admin and create a new board (Boards) and make note of the ID.
Make another file called "secondboard.aspx" (or whatever) and change
call to YAF to include the boardid #:

<form runat="server" enctype="multipart/form-data">
<yaf:forum boardid="2" runat="server"/>
</form>

(Boardid
is whatever you want… you could have it reference a million different
boards if you create them — categoryid is also supported.)

Get Adobe Flash playerPlugin by wpburn.com wordpress themes