Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michael Griffith

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Stopping double submits



        Dim sb As New System.Text.StringBuilder()
        sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
        sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
        sb.Append("this.value = 'Please Wait...';")
        sb.Append("this.disabled = true;")
        sb.Append(Me.Page.GetPostBackEventReference(Me.btnSubmit))
        sb.Append(";")
        btnSubmit.Attributes.Add("onclick", sb.ToString())

Setting focus to a field in asp.net

This code does a simple field focus in asp.net.

    Protected Sub setFieldFocus(ByVal ctrl As System.Web.UI.Control)
        Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" + ctrl.ClientID + "').focus() </SCRIPT>"
        ClientScript.RegisterStartupScript(Me.GetType, "focus", s)
    End Sub

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindData()
        End If
        setFieldFocus(txtSpecies)
    End Sub

.net pipeline optimization for www sites.

Put the following code in the system.web part of the web.config file of the site you are working on.
It will take out the session tracking and authorization http modules for your application.

      <httpModules>
        <!-- Remove unnecessary Http Modules for faster pipeline -->
        <remove name="Session" />
        <remove name="WindowsAuthentication" />
        <remove name="PassportAuthentication" />
        <remove name="AnonymousIdentification" />
        <remove name="UrlAuthorization" />
        <remove name="FileAuthorization" />
      </httpModules>


and yes I copied this from someone else, unfortunately I don't remember who.

Web Config and code for forms authentication in .net

Here's the forms authentication code that I always seem to forget.

Blatantly stolen from http://www.4guysfromrolla.com/webtech/110701-1.2.shtml and http://support.microsoft.com/kb/316871

Sub Submit_OnClick(sender as Object, e as EventArgs)
  If MyCustomMethod (txtUserName.Text, txtPassword.Text) Then    
      FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, False)
  Else
      ' Invalid credentials supplied, display message
      lblMessage.Text = "Invalid login credentials"
  End If
End Sub


<configuration>
	<system.web>
		<authentication mode="Forms" >
			<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
			</forms>
		</authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
		<authorization>
			<deny users="?" /> 
		</authorization>
	</system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
		<location path="default1.aspx">
		<system.web>
		<authorization>
			<allow users ="*" />
		</authorization>
		</system.web>
		</location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder.  -->
		<location path="subdir1">
		<system.web>
		<authorization>
			<allow users ="*" />
		</authorization>
		</system.web>
		</location>
</configuration>

Gathering html id's from asp.net

The basic idea here is to pull the id's from asp.net so that it can be used in a javascript environment.

<input id="GetLocation" type="button" onclick="getLocation(<%=tbStreet.clientID %>.value + ' ' + <%=tbCity.clientID %>.value + ' ' + <%=tbState.clientID %>.value + ' ' + <%=tbZip.clientID %>.value,'<%=lblLocation.clientID %>');" value="Get Location" />
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS