Archive for the ‘ ASP.NET ’ Category

Javascript Confirmation with ASP.NET Validations

It was difficult for me to find out how to use submit confirmation while using ASP.NET validations in Web Form. This following one is the Java Script Function to be used.

   function ConfirmSubmit() {

        if (Page_IsValid) {

            return confirm('Do you want add this User?');

        return Page_IsValid;

Use it this way with your Submit Button.

onclientclick="return ConfirmSubmit();"

A Rahim Khan

StateServer Session Mode with Class (Object) ASP.NET

First of all, ASP.NET State Service is to be on to use StateServer Session.
Place this piece of code in your Web.Config File.

sessionState mode="StateServer" stateConnectionString="tcpip=" cookieless="false" timeout="120"

Now you can start using StateServer Session, rest of the steps are same all kind of Sessions.

However, if you are storing any Class’s Object in StateServer Session, this particular class requires Serialization. Have a look at this User Class, it’s object can be stored in StateServer Session. Continue reading

Get Web User IP Address for Local Network Web Application

This is going to work only for Local network Web Application, it will return proxy’s IP if anyone using Proxy to connect your Web Application.

string userIpAddress = Request.UserHostAddress.ToString();

A Rahim Khan

Set Value to ASP.NET Password Mode TextBox

You can’t directly set value for Password Mode TextBox like Normal Single/Multiline TextBox. You got to do it like

userPasswordTextBox.Attributes["value"] = "PASSWORD";
retypePasswordTextBox.Attributes["value"] = "RETYPE PASSWORD";

A Rahim Khan

firing client validation before client confirmation in

Client Side Confirmation is simple one using Java Script, Just write this single line in OnClienClick Properties of your Submit Button and set up Client Confirmation Box at Button Click Event.

return confirm('Do you want add this Problem?');

Now, when you have Java Script validation in your page this kind of Client Confirmation will create difficulties. More specifically, at Button Click Confirmation Box will will appear first, if client click Ok Button, Web Page will be submitted to server skipping Client Side Validation. Continue reading

Cookie with ASP.NET (C#)

Here, I am providing some helpful code snippets to work with Cookie in ASP.NET. if you don’t have any idea on Cookie, please surf here. This will help to get good idea on Cookie.

This one shows how to set and save values in Cookie.

//Set Cookie
HttpCookie userCookie = new HttpCookie("UserInfo");
userCookie["userName"] = TextBox1.Text;
userCookie["userPassword"] = TextBox2.Text;
userCookie.Expires = DateTime.Now.AddDays(3);

Continue reading

Session with ASP.NET(C#)

if you are new with session, you are in the right place. Here, I will try to put together some code snippets to show various uses of Session. Let’s start with how to assign a Integer value in Session followed by how to retrieve it.

// Assign "userCode" variable to Session  
int userCode = 7;
Session.Add("UserCode", userCode);

//Retrieve "userCode" from Session
int userCode;
userCode= (int)Session["UserCode"];

Continue reading