samedi 27 juin 2015

How to implement Login functionality using ASP.NET WebForms and existing SQL Server database?

I have a SQL Server database that I made using Visual Studio's LocalDB. It has 5 tables, one for the Employee information and credentials, one for the location codes of the offices of the company and others for the meetings he attended and the tasks assigned to him.

I am mainly looking to implement Login functionality on my WebApp. How do I access the SQL database and implement Login? I have currently connected the database and used ADO.NET Entity Model to access the database. I am looking to avoid stored procedures. It would be best if the someone explained how to do this with ADO.NET Entity Model and the Login control.

Edit image and delete row from GridView using c# ASP.NET

I have a problem.I need to edit and delete row of GridView using C# ASP.NET.I tried once and able to fill the data in textbox after click on edit button but i have also one image to edit and i need when user will click on edit image the image will also display in proper place to edit.In case of delete part i have image in anchor tag and i need which event i should pass from GridView and define in code behind page so that i can do the operation.I am explaining my code below.

faq.aspx:

<div class="col-md-6">
                                                <label for="question" accesskey="T"><span class="required">*</span> Question</label>
                                                <asp:TextBox ID="TextBox1" runat="server"  size="30" value="" name="question" ></asp:TextBox>
                                                <div id="noty" style="display:none;" runat="server"></div>
                                                <label for="answer" accesskey="A"><span class="required">*</span> Answer</label>
                                                <asp:TextBox ID="TextBox2" runat="server"  size="30" value="" name="answer" ></asp:TextBox>
                                                <div id="Div1" style="display:none;" runat="server"></div>
                                            </div>
                                            <div class="col-md-6 bannerimagefile">
                                                <label for="insertimage" accesskey="B"><span class="required">*</span> Insert Image</label>
                                                <asp:FileUpload runat="server" class="filestyle" data-size="lg" name="insertimage" id="FileUpload1" onchange="previewFile()" />
                                                <label for="bannerimage" accesskey="V"><span class="required">*</span> View Image</label>
                                                <div style="padding-bottom:10px;">
                                                    <asp:Image ID="Image3" runat="server" border="0" name="bannerimage" style="width:70px; height:70px;"   />
                                                </div>
                                                <div class="clear"></div>
                                                <asp:Button ID="Button1" runat="server" Text="Submit" class="submit" 
                                                    onclick="Button1_Click" />
                                                </div>
                                        </div>
                                </div>

                            </div>
                            <!--end_1st_faq_add_div-->
                            <!--2nd_list_banner_view_div-->
                            <div class="widget-area">
                                <h2 class="widget-title"><strong>FAQ List</strong></h2><asp:HiddenField ID="HiddenField1"  runat="server" />
                                <div class="streaming-table margin-top-zero padding-top-zero">
                                    <div class="table-responsive">
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
                                            Width="100%" CssClass="table table-striped table-bordered margin-top-zero" 
                                            onselectedindexchanged="GridView1_SelectedIndexChanged">
                                        <Columns>
                                           <asp:TemplateField HeaderText="Sl No">
                                           <ItemTemplate>
                                           <asp:Label ID="faqid" runat="server" Text='<%#Eval("FAQ_ID") %>'></asp:Label>
                                           </ItemTemplate>
                                           </asp:TemplateField>
                                           <asp:TemplateField HeaderText="Question" >
                                           <ItemTemplate>
                                           <asp:Label ID="question" runat="server" Text='<%#Eval("Question") %>'></asp:Label>
                                           </ItemTemplate>
                                           </asp:TemplateField>
                                           <asp:TemplateField HeaderText="Answer" >
                                           <ItemTemplate>
                                           <asp:Label ID="answer" runat="server" Text='<%#Eval("Answer") %>'></asp:Label>
                                           </ItemTemplate>
                                           </asp:TemplateField>
                                           <asp:TemplateField HeaderText="Image" >
                                           <ItemTemplate>
                                           <asp:Image ID="Image1" runat="server" border="0" name="bannerimage" style="width:70px; height:70px;" ImageUrl='<%# "/Upload/" + Convert.ToString(Eval("Image")) %>'  /> 
                                           </ItemTemplate>
                                           </asp:TemplateField>
                                           <asp:TemplateField HeaderText="Action" >
                                           <ItemTemplate>
                                           <a href="" data-toggle="tooltip" title="" class="btn btn-xs btn-success" data-original-title="Edit" id="editbtn" ><i class="fa fa-edit"></i></a>
            <a href=" " data-toggle="tooltip" title="" class="btn btn-xs btn-danger" data-original-title="Delete"><i class="fa fa-times"></i>
                                           </ItemTemplate>
                                           </asp:TemplateField>
                                        </Columns>
                                        </asp:GridView>
                                    </div>

faq.aspx.cs:

protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
        {
            int index = Convert.ToInt32(e.NewSelectedIndex);
            TextBox1.Text = GridView1.Rows[index].Cells[1].Text;
            TextBox2.Text = GridView1.Rows[index].Cells[2].Text;
            HiddenField1.Value = GridView1.Rows[index].Cells[0].Text;
            Button1.Text = "Update";
        }

As I am new to ASP.NET please help me to resolve this issue.

Asp.net MVC Loading Parent View from the actionlink of PartialView using Ajax not working

I have a situation where I need to call ParentView from its partial view. Like I have list of ToDos in Partial view where Ajax actionlink is used to edit the data in parent by passing its id. The same is working without using Ajax as it is manipulating url by putting querystring. But we would like to have internal call with Ajax which is not firing.

The code we are using is like that:

<li>@Ajax.ActionLink(@item.ToDoTitle, "Index", new { tdid = @item.ToDoId }, new AjaxOptions { UpdateTargetId = "saved", InsertionMode = InsertionMode.Replace, HttpMethod="POST" })</li>

and controller is like that:

public ActionResult Index(int tdid =0)
    {
        if (tdid !=0)
        {
            ToDo t = new ToDo();
            t.ToDoTitle = "Ramlal";
            t.ToDoDesc = "Shyamlal";
            t.ToDoId = tdid;
            return Json(t);
        }
        else
        {
            return View();
        }
    }

Updating table in ms sql server for asp.net mvc project but class definations disapeared

I updated the tables in MS SQL Server by changing a lot of the data types stored. To update this change in my ASP.NET MVC project, I refreshed the database connection, updated the model from database in my .edmx diagram and tranformed all T4 templates.

However, now all my class definitions for each table have disappeared. Is there a way to regenerate these .cs documents?

Any help would be appreciated.

I'm trying to deploy to Microsoft Azure this ASP.NET MVC project, the template of which I got from Xamarin. I've spent, literally, 20 hours trying to figure out why deployments keep failing. I've tried both

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

and

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets"     Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="true" />

for the Imports, as per suggestions on the web. I've also added

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
</configuration>

and I've toggled between Classic and Integrated for Azure's Managed Pipeline Version setting. I've toggled between .NET versions 3.5 and 4.5 for Azure's .NET Framework Version setting (Xamarin doesn't tell me which version I'm using).

You can actually look here and see all my commits where I've messed with configuration settings to try and get this damn thing to work. It's like Microsoft is trying to force me to publish through Visual Studio rather than GitDeploy (what I'm trying to do).

The error I'm getting right now is

error MSB4057: The target "pipelinePreDeployCopyAllFilesToOneFolder" does not exist in the project.

Anyways, I'm out of ideas, unless you guys have any.

Ajaxfied RadGrid RadCombo FilterTemplate

I want to know how to implement custom filter in RadGrid.

I have a Ajaxfied RadGrid and datasource is binded in NeedDatasource event. The RadGrid has five columns.. In that, I want to change the filter of one of the column to selectable filter..

So, I added a FilterTemplate and added the RadComboBox inside to it..

Initially, I hardcoded all the RadComboBox item in the design time itself.. Binded a javascript to clientside_selectedchanged event.. This approach worked fine..

When I binded RadComboBox with collection (List) in the code behind.. The filtering didn't work.. I binded the RadComboBox in GridItemDataBound or GridItemCreated event.. But no luck..

Any help.. will be very much useful to me.. I spent nearly two days but I didn't any direction...

Custom Filter Code The following is sample code which I copied from my project and pasted here.. I have changed the field names alone..

Filter Template:

<telerik:GridBoundColumn DataField="DepartmentDescription" Groupable="true" HeaderText="Program" UniqueName="DepartmentDescription">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxDepartmentDescription" runat="server"
            AppendDataBoundItems="true"
            DataTextField="DepartDesc"
            DataValueField=" DepartDesc "
            OnClientSelectedIndexChanged=" RadComboBoxDepartmentDescriptionIndexChanged"
            OnDataBound="RadComboBoxAllFilters_OnDataBound"
            SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("DepartmentDescription ").CurrentFilterValue %>'
            Width="100px">
            <Items>
                <telerik:RadComboBoxItem Text="All" Value="" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlockProgram" runat="server">
            <script type="text/javascript">

                function RadComboBoxDepartmentDescriptionIndexChanged(sender, args) {
                    var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                    tableView.filter("DepartmentDescription", args.get_item().get_value(), "EqualTo");
                }
            </script> 
        </telerik:RadScriptBlock>
    </FilterTemplate>
    <ItemStyle Wrap="False" />
    <HeaderStyle Wrap="false" />
</telerik:GridBoundColumn>

RadGrid DataBinding Code

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
(sender as RadGrid).DataSource = employeeList//This is a list of employee of values.. which comes from service layer.. of type .. List<Employee>
}

RadGrid UI Code

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div>
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="true"
            OnNeedDataSource="RadGrid1_NeedDataSource"
..other code I removed it.. like the grid events and bound columns definitions
        </telerik:RadGrid>

RadComboBox Filter DataBinding Code in the Code Behind:

Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

If TypeOf e.Item Is Telerik.Web.UI.GridFilteringItem Then

    'Populate Filters by binding the combo to datasource
    Dim filteringItem As Telerik.Web.UI.GridFilteringItem = CType(e.Item, Telerik.Web.UI.GridFilteringItem)
    Dim myRadComboBox As Telerik.Web.UI.RadComboBox = DirectCast(filteringItem.FindControl("RadComboBoxDepartmentDescription"), Telerik.Web.UI.RadComboBox)

    myRadComboBox.DataSource = departmentList; //This is a collection which comes from service layer… and the type is List<Department>
    myRadComboBox.DataTextField = " DepartmentDescription"
    myRadComboBox.DataValueField = " DepartmentDescription"
    myRadComboBox.DataBind()

End If

Even I pasted the same code in ItemCreated Event as well but no luck…

IIS Redirects me to another URL

I have a website on my local computer. It is a CMS(DNN) Website which is for long time on my computer. it is on 127.0.0.1:80 but I set an address for it in the host file. It was working well till today that when I tried to visit it, I was redirected to another address which I had set on the host file too. I deleted that address from the host file and restarted my computer but I still redirected to that address.