Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Friday, January 17, 2014

Telerik RadGrid PagerTextFormat


PagerTextFormat text must start with Navigate pages {4}

PagerTextFormat="Navigate pages {4} {1} sayfa, {5} Kayıt"

Monday, April 1, 2013

telerik scheduler timeline view render problem

if you are using Telerik RadScheduler TimelineView,

<TimelineView
        UserSelectable="false"
        GroupBy="Room"
        GroupingDirection="Vertical"
        ColumnHeaderDateFormat="dd"
        HeaderDateFormat="M"
        SlotDuration="12:00:00"
        TimeLabelSpan="2"
        ShowInsertArea="false"></TimelineView>

TimeLabelSpan property gives you some trouble such as alignment problems. to solve the issue, set the code snippet to your css file.

.rsHidden { display:table-row !important;}

Wednesday, February 27, 2013

Telerik RadWindow Set Behaviors Client Side



//this is radbutton onclientclicking event
function openWindow(sender, args) {
 
    //create window
    var parentPage = GetRadWindow().BrowserWindow;

    //open window
    var win = parentPage.radopen("url_here, null);

    //set properties
    win.setSize(400, 600);
    win.setTitle("ActionLogs Window");
    win.setActive();
    win.setModal(true);

//set behaviors
    win.set_behaviors(winBehaviours.Close | winBehaviours.Move);

    //prevent postback
    args.set_cancel(true);

}


var winBehaviours = {

    None: 0,
    Resize: 1,
    Minimize: 2,
    Close: 4,
    Pin: 8,
    Maximize: 16,
    Move: 32,
    Reload: 64
}


function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement && window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}



Saturday, February 23, 2013

asp.net databinder eval DateTime Format

<%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:d}")%>

Monday, January 14, 2013

Telerik CheckBox Code Sample

<telerik:RadButton ID="btnToggle"
                              runat="server"
                              ToggleType="CheckBox"
                              ButtonType="LinkButton"
                              Checked="true"
                              ReadOnly="true">
<ToggleStates>
           <telerik:RadButtonToggleState Text="I'm attending."
                                                           PrimaryIconCssClass="rbToggleCheckboxChecked" />
           <telerik:RadButtonToggleState Text="I'm NOT attending."
                                                           PrimaryIconCssClass="rbToggleCheckbox" />
</ToggleStates>
</telerik:RadButton>

telerik radgrid onitemcommand not fire

check viewstatemode in the page ViewStateMode="Disabled" and also in the web config enableViewState="false"

change from ViewStateMode="Disabled"  to ViewStateMode="Enabled"
change from enableViewState="false" to enableViewState="true"

Monday, November 12, 2012

telerik grid masked column not working


this is the dummy solution.



RadMaskedTextBox dummyTextBox = new RadMaskedTextBox(); 
protected void ClientRadGrid_ItemDataBound(object sender, GridItemEventArgs e) 
{ 
   if (e.Item is GridDataItem) 
   { 
        GridDataItem item = (GridDataItem)e.Item; 
        dummyTextBox.Mask="+## (###) ### ## ##"; 
        dummyTextBox.Text = item["Phone"].Text; 
        item["Phone"].Text = dummyTextBox.TextWithPromptAndLiterals; 
    } 
}

Wednesday, August 29, 2012

repeater onitemcommand not working

Change red to yellow

web.config

>pages enableviewstate="false">
>pages enableviewstate="true">

Page Markup

ViewStateMode="Disabled"
ViewStateMode="Enabled"

Monday, August 27, 2012

subdomain HttpContext.Current.Server.MapPath Problem

const String folderName = "App_Data/Database"; not works 
const String folderName = "~/App_Data/Database"; works

Saturday, August 25, 2012

Saturday, August 11, 2012

Create Image Thumb Name


if file name contains in path, no problem.


 String CreateThumbName(String fullPath)

        {
            //get file name
            var onlyFilename = System.IO.Path.GetFileNameWithoutExtension(fullPath);
            //name with extension
            var nameWithExt = System.IO.Path.GetFileName(fullPath);
            //just extension
            var ext = System.IO.Path.GetExtension(fullPath);
            //create thumb name
            var thumbName = String.Format("{0}_thumb{1}", onlyFilename, ext);
            //replace file name with thumb name
            var result = fullPath.Replace(nameWithExt, thumbName);
           
            //return result
            return result;
        }


Sample

var fullPath = "c:\windows\MyFolder\my.jpg"
var result = CreateThumbName(fullPath);

Console.WriteLine(result);

Output

c:\windows\MyFolder\my_thumb.jpg



Asp.net Convert AbsolutePath to RelativePath


I wrote step by step to be clear. use this method as extension could be nice.
 String ToRelative(String absolute)
        {
            //getting root portion
            var root = HttpContext.Current.Server.MapPath("/");
            //removing root portion
            var result = absolute.Replace(root, "");
            //replace backslash-spash
            result = result.Replace("\\", "/");
            //finalize the path adding first char as slash
            result = String.Format("/{0}", result);
            //good to go
            return result;
        }

Thursday, July 5, 2012

WCF Json Service Method Argument null Problem

Do NOT use "url" as a argument name.

Wcf Service Method

 [OperationContract]
 [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json,
         RequestFormat= WebMessageFormat.Json)]
PageDTO PageByUrl(String url,String language);  --> PageDTO PageByUrl(String title,String language); 


-----------------------------------------------------------------------

Requested Url:

http://localhost:2222/tr-TR/test-page-1
-----------------------------------------------------------------------


Jquery Ajax Call


<script type="text/javascript">

    $(document).ready(function () {
     
        data = window.location.pathname.split("/");
        urlStr = data[data.length -1];
        languateStr = data[data.length - 2];

        var data = new Object();
        data.url = urlStr;   ---> data.title=urlStr;
        data.language = languateStr;

        //var xxx = $.toJSON(data);
        //result: {"url":" test-page-1","language":"tr-TR"}

        caller_dynamic(data);
    });


    var menuUrl = "http://localhost:9000/PublicService.svc/PageByUrl";

    function caller_dynamic(mydata) {
        $.support.cors = true;
        $.ajax({
            type: "POST",
            url: menuUrl,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: $.toJSON(mydata),
            success: function (data) {
                $("#content").html(data.Content);
            },
            error: function (xhr) {
                alert(xhr.responseText);
            }

        });
    }
     < /script>

---------------------------------------------------------------------

public PageDTO PageByUrl(String url, String language) --> (String title, String language)
        {
            try
            {
                var publicBS = unityContainer.Resolve();
                var page = publicBS.PageByUrl(title);
                return page;
            }
            catch (Exception ex)
            {
                throw DynFaultException.Instance.CreateFault(ex);
            }
        }



Conclusion

if url is null, do NOT panic. just change the name of the argument name url to title.





Tuesday, July 3, 2012

Javascript Page Document ready, PageLoad, Application Init


$(document).ready()
  • Ideal for onetime initialization.
  • Optimization black magic; may run slightly earlier than pageLoad().
  • Does not re-attach functionality to elements affected by partial postbacks.
pageLoad()
  • Unsuitable for onetime initialization if used with UpdatePanels.
  • Slightly less optimized in some browsers, but consistent.
  • Perfect for re-attaching functionality to elements within UpdatePanels.
Application.Init
  • Useful for onetime initialization if only ASP.NET AJAX is available.
  • More work required to wire the event up.
  • Exposes you to the “sys is undefined” error if you aren’t careful.

Thursday, June 21, 2012

ASP.NET Configure Json Serialization MaxLenght recursionLimit

Schema

<jsonSerialization 
      maxJsonLength="number" 
      recursionLimit="number">
    <converters>... </converters>
</jsonSerialization>

Defaults

The default length is 102400
The default recursion limit is 100

Sample

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="500000">
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>

Short Sample

<jsonSerialization maxJsonLength="50" recursionLimit="10" />

Resource:

http://msdn.microsoft.com/en-us/library/bb513882.aspx

Friday, June 15, 2012

Register Tag Prefix Of Telerik Control in Web.config


Clear the register tag from the page.

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>


Place the code snipped in the web.config. 

<system.web>
    <pages>
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
      </controls>
    </pages>
  </system.web>

Wednesday, June 6, 2012

LINQ group by Count and Avarage/avg


var query = from q in this.context.TRAINING_PLAYER
                        group q by q.session_id into grp
                        select new
                        {
                            sessionId = grp.Key,
                            count = grp.Select(p => p.player_id).Distinct().Count()
                        };

            var mean = query.Average(p => p.count);

Tuesday, June 5, 2012

ASP.NET JSON Serialization and Deserialization

You should reference the Assembly System.Web.Extensions.dll, v4.0.30319

Serialize

JavaScriptSerializer js = new JavaScriptSerializer();
MyClass c = new MyClass();
c.Name = "Tugbay";
c.BirthDate = 1981;

String serializedString = js.Serialize(c);

Result

{"Name":"Tugbay","BirthDate":"1981"}


Deserialize

JavaScriptSerializer js = new JavaScriptSerializer();

var instance = js.Deserialize(serializedString);

Console.WriteLine("Name:" + instance.Name);
Console.WriteLine("BirthDate:" + instance.BirthDate);

Result

Name: Tugbay
BirthDate: 1981

Sunday, May 6, 2012

Asp.Net Routing is not working



add the below code snipped to the web.config
   < system.webServer>
     < modules runAllManagedModulesForAllRequests="true"/>
   < /system.webServer>


AND also


in the global.asax fıle, find the Application_Start(object sender, EventArgs e) event, add the code to the event.



        protected void Application_Start(object sender, EventArgs e)


        {

            routes.Ignore("{resource}.axd/{*pathInfo}");
            routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
            routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
            routes.Ignore("{*allpng}", new { allpng = @".*\.png(/.*)?" });
            routes.Ignore("{*allgif}", new { allgif = @".*\.gif(/.*)?" });
            routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
            routes.Ignore("{*allbmp}", new { allbmp = @".*\.bmp(/.*)?" });

            RegisterRoutes(RouteTable.Routes);
            RouteTable.Routes.Add("about-browse", new Route("aboutus", new PageRouteHandler("~/About.aspx")));

        }

Wednesday, May 2, 2012

Telerik RadGrid RowSelected ClientSide Find Data in Row


< ClientSettings>
< ClientEvents OnRowSelected="RowSelected" />
< /ClientSettings>

< MasterTableView ClientDataKeyNames="Property1" >

function RowSelected(sender, eventArgs) {
var val = ventArgs.getDataKeyValue("Property1");

}