10/21/09

Deploying website to remote server

Now i need to deploy all the site to remote hosting, with all pages and all database structure.
Also i want to make some users and roles so the site can be usable.
How to do it without copying the data from local to remote the database?
There is the way:
ASP.NET Config Tool


You can set the users roles and setting on remote site with ASP.NET Config Tool.
Note:When  you want ASP.NET Config Tool to work on not default aspntedb.mdf databse
you need to configure it first - How to do it? you can read this article that explains simple and clearly all about this tool.

To doing this you need only to change the connection string of providers (Rolemanager and Membership Customuized providers in web.config )

<connectionStrings>
   
 <add name="MyConnectionString"
    connectionString="Data Source=my_server;Initial   Catalog=my_DB;User my_user;Password=my_passwd;Integrated Security=False;"
     providerName="System.Data.SqlClient" />
</connectionStrings>

<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
       <providers>
          <add connectionStringName="MyConnectionString"
             name="CustomizedRoleProvider"
             type="System.Web.Security.SqlRoleProvider"
             applicationName="/M-survey1" 
             />
       </providers>
</roleManager>
<membership defaultProvider="CustomizedMembershipProvider" >
       <providers>
        
         <add connectionStringName="MyConnectionString"
               name="CustomizedMembershipProvider"
               requiresQuestionAndAnswer="false"
               type="System.Web.Security.SqlMembershipProvider"
               applicationName="/M-survey1"
              />
        
</providers>

Important!

After congifuring the users and members of the application
I found that the exisitnig usrs cannot logion and new registered users cannot access the role restricted areas.
after investigation I found that
the reason to this behavior was Appliction Name field somehow had different values for newly registered and for registered with aspNetConfiguration Tool users.


10/9/09

View Answerers Button



This button must show the list of users who answered the survey. Which survey? The one with its checkbox checked, of course :
This code is for finding which survey is checked (selected)
    private int findCheckedSurvey()
    {
        int survId = -1;
        foreach (RepeaterItem ri in Repeater1.Items)
        {
            CheckBox chkBox = (CheckBox)ri.FindControl("CheckBox1");
            if (chkBox != null && chkBox.Checked)
            {
                HiddenField hf;
                hf = (HiddenField)ri.FindControl("surveyID");
                survId = Convert.ToInt32(hf.Value);
                return survId;
            }
        }
        return survId;

    }


It means that only one survey allowed to be checked at once. How to force user not to check
more than one?
I wrote this code that unchecks the other checkboxes once user checked one of the surveys:
    protected void unCheckOthers(object sender, EventArgs e)
    {
        foreach (RepeaterItem ri in Repeater1.Items)
        {
            CheckBox chkBox = (CheckBox)ri.FindControl("CheckBox1");
            CheckBox c = (CheckBox)sender;
            bool thisIs=false;
            if (c.NamingContainer == chkBox.NamingContainer)
            {
                thisIs = true;
            }
   
           
            if (chkBox != null && chkBox.Checked && !thisIs)
            {
                chkBox.Checked = false;
            }
        }
    }

Note, that all the checkBoxes have the same ID property, so if we want the newly checked checkbox to stay checked we must use NamingContainer property which gets the unic identifier of repeater tags.
Important:If you want your checkboxes CheckedChacnged event to be handled at server code - you must set IsPostBack property to TRUE 

9/29/09

Validation of Publish button

I want that publish/unpublish command will be performed only if the survey have at least one question.
If the publish button pressed in the zero -question line - the user must get the red warning message:

You cannot publish survey with zero questions


But how to do it? The validate function cannot receive any additional parameters except
object sender, ServerValidateEventArgs e
And we cant even figure out which repeater item sended the command since the publish button not requires any item checkboxses to be checked.

Custom validator:

<asp:CustomValidator ID="CustomValidator2" runat="server"
ErrorMessage="You cannot publish survey with zero questions"
ValidationGroup="zeroQuestions" Display="Dynamic" OnServerValidate="IsZeroQuestions">
</asp:CustomValidator>

It raises the server-validation function IsZeroQuestions
how can this function "know" what the questions number of line(Repeater Item) whose raised it?



Well, it means i need to change the way the Publish/Unpublish button working:
From now it will work this way:
protected void PublishThisSurvey(object sender, RepeaterCommandEventArgs e)
    {
        RepeaterItem ri = Repeater1.Items[e.Item.ItemIndex];
        CheckBox chkBox = (CheckBox)ri.FindControl("CheckBox1");
        chkBox.Checked = true

        Validate("zeroQuestions");

        if (!Page.IsValid)
        {
        CustomValidator2.ErrorMessage = "Cannot publish this
            survey with zero questions";


            chkBox.Checked = false;
            return;

        }


        HiddenField hf;
        hf = (HiddenField)ri.FindControl("surveyID");
        int surveyID = Convert.ToInt32(hf.Value);

HiddenField isPhf = (HiddenField)ri.FindControl("IsPublished_hf");
        bool bIsPublished = Convert.ToBoolean(isPhf.Value);
      

        //turn upside
        bIsPublished = (bIsPublished) ? false : true;
        clsDataAccess myclass = new clsDataAccess();
        myclass.UpdateSurveyPublished(surveyID, bIsPublished);
        Repeater1.DataBind();
    }



and the trigger will be ItemCommand of Repeater:
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SurveysSqlDataSource" OnItemCommand="PublishThisSurvey">                                    

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...