http___programlamaipuclari.blogspot.com.tr_2013_01_01_archive.html_1.xml
1.1 2.1 2.2 2.3 3.1 4.1 4.2 4.3 5.1 6.1 7.1 8.1 8.2 8.3 8.4 9.1 10.1 10.2 11.1 13.1 14.1 15.1 16.1 17.1 18.1 19.1 20.1 22.1 24.1 26.1 30.1 31.1 32.1 33.1 39.1 40.1 41.1 41.2 42.1 43.1 44.1 46.1 48.1 48.2 50.1 50.2 50.3 52.1 53.1 53.2 54.1 54.2 55.1 55.2 56.1 56.2 60.1 62.1 63.1 64.1 65.1 69.1 71.1 72.1 74.1 75.1 76.1 77.1 78.1 79.1 80.1 80.2 81.1 81.2 82.1 83.1 84.1 85.1 89.1 91.1 92.1 94.1 95.1 96.1 97.1 98.1 98.2 98.3 99.1 99.2 99.3 99.4 99.5 99.6 99.7 99.8 100.1 100.2 100.3 100.4 100.5 101.1 101.2 102.1 102.2 103.1 103.2 104.1 105.1 106.1 107.1 108.1 108.2 109.1 109.2 110.1 111.1 112.1 113.1 114.1 115.1 116.1 117.1 117.2 118.1 119.1 119.2 119.3 120.1 121.1 122.1 123.1 125.1 126.1 126.2 128.1 130.1 130.2 132.1 134.1 134.2 136.1 137.1 139.1 139.2 140.1 140.2 140.3 141.1 141.2 145.1 146.1 147.1 147.2 148.1 149.1 149.2 149.3 150.1 151.1 152.1 153.1 154.1 154.2 155.1 156.1 157.1 157.2 158.1 159.1 160.1 161.1 162.1 165.1 166.1 167.1 170.1 171.1 172.1 173.1 174.1 177.1 178.1 179.1 180.1 181.1 182.1 182.2 183.1 183.2 184.1 185.1 186.1 186.2 187.1 188.1 189.1 190.1 191.1 194.1 195.1 196.1 199.1 200.1 201.1 202.1 203.1 206.1 207.1 209.1 210.1 211.1 211.2 213.1 215.1 215.2 217.1 218.1 220.1 220.2 220.3 220.4 224.1 225.1 227.1 228.1 230.1 232.1 234.1 235.1 237.1 239.1 240.1 242.1 246.1 247.1 248.1 249.1 249.2 250.1 251.1 252.1 253.1 254.1 255.1 256.1 257.1 258.1 259.1 261.1 262.1 262.2 263.1 263.2 264.1 265.1 266.1 267.1 268.1 272.1 273.1 277.1 278.1 280.1 280.2 280.3 282.1 283.1 284.1 286.1 287.1 287.2 288.1 288.2 289.1 290.1 292.1 293.1 293.2 293.3 295.1 295.2 296.1 297.1 297.2 297.3 297.4 300.1 301.1 301.2 302.1 304.1 305.1 306.1 306.2 307.1 307.2 308.1 308.2 310.1 310.2 310.3 310.4 311.1 312.1 312.2 314.1 314.2 316.1 316.2 316.3 319.1 320.1 321.1 322.1 322.2 324.1 325.1 325.2 325.3 325.4 325.5 325.6 325.7 325.8 327.1 328.1 328.2 328.3 328.4 328.5 329.1 330.1 331.1 331.2 333.1 335.1 337.1 339.1 339.2 339.3 340.1 341.1 342.1 343.1 344.1 345.1 346.1 347.1 347.2 347.3 348.1 349.1 351.1 352.1 354.1 355.1 356.1 356.2 357.1 358.1 358.2 359.1 360.1 360.2 362.1 363.1 363.2 363.3 365.1 366.1 367.1 369.1 370.1 371.1 372.1 373.1 374.1 374.2 374.3 375.1 376.1 377.1 378.1 379.1 380.1 381.1 382.1 382.2 382.3 383.1 384.1 385.1 386.1 387.1 388.1 389.1 389.2 390.1 391.1 391.2 392.1 393.1 393.2 394.1 395.1 396.1 396.2 396.3 397.1 398.1 399.1 400.1 401.1 402.1 402.2 402.3 402.4 402.5 402.6 402.7 402.8 404.1 405.1 406.1 408.1 408.2 409.1 410.1 412.1 413.1 414.1 415.1 416.1 416.2 417.1 418.1 419.1 420.1 421.1 421.2 421.3 421.4 421.5 422.1 423.1 424.1 424.2 425.1 427.1 427.2 428.1 429.1 429.2 429.3 429.4 430.1 430.2 430.3 431.1 432.1 433.1 434.1 435.1 437.1 437.2 438.1 439.1 441.1 442.1 443.1 444.1 446.1 447.1 449.1 453.1 453.2 453.3 453.4 454.1 454.2 454.3 455.1 456.1 458.1 459.1 460.1 462.1 464.1 466.1 467.1 468.1
Database Installation using VS setup Database installation is common task in setup programming. Here are the steps to install sql server database with setup using custom action. the summary is following Search Engine style paging in asp.net(C#) When a large number of records are to be displayed and total number of records is variable in nature then search engine style paging is the best approach. For a search query, we need to pass start record number and page size for paging. In the most search engine, the start index is passed using querystring. See following, Google uses “start” query string parameter. See following, Google uses “start” query string parameter. Facebook, Twitter, LinkedIn, Digg, YouTube, Flicker and Google API and .NET libraries Facebook, Twitter, LinkedIn, Digg, YouTube, Flicker, Orkut..etc are the most popular in the Web. Now these are becoming a part of website and web application. These provide API to use the service in your web app. Here is the links of API and sample wrapper for .NET developer. Maintain Scroll Position of ASP.NET Panel after postback Asp.NET Panel is a div, so in following code, javascript is used to maintain scroll after postback and cookies is used to store scroll position. For first time, we need not to set scroll so it is detected using IsPostback property. Replace pnlTree to your panel ID in above code and Enjoy it. var IsPostBack= ' '; window.onload = function(){ var strCook = document.cookie; if(strCook.indexOf("!~")!=0){ var intS = strCook.indexOf("!~"); var intE = strCook.indexOf("~!"); var strPos = strCook.substring(intS+2,intE); if (IsPostBack=='True') document.getElementById(" ").scrollTop = strPos; else document.cookie = "yPos=!~0~!"; function SetDivPosition(){ var intY = document.getElementById(" ").scrollTop; document.title = intY; document.cookie = "yPos=!~" + intY + "~!"; Replace pnlTree to your panel ID in above code and Enjoy it. Sort CheckedNodes (TreeNodeCollection) in ASP.NET Treeview Generally it is required to sort all selected item in treeview and make it in CSV format. Suppose we require node value which is not same as text then we need to sort checked nodes (on the basis of text), not text only, So that we can retrieve node value and other node properties also. The following code will sort TreeNodeCollection on text basis: The following code will sort TreeNodeCollection on text basis: private TreeNodeCollection SortTreeNode(TreeNodeCollection nodeList) for (int i = 0; i < nodeList. for (int j = i + 1; j < nodeList. Count; j++) if (nodeList[i]. Text. CompareTo(nodeList[j]. TreeNode temp = nodeList[i]; nodeList. RemoveAt(i); nodeList. AddAt(i,nodeList[j-1]); nodeList. RemoveAt(j); nodeList. AddAt(j, temp); return nodeList; Handle Cross-site scripting Error in ASP.NET Our object is to prevent cross-site scripting and customize error message generated by cross-site exception in asp.net. First Method: In web.config set validateRequest = true for complete site. You can disable it for a particular page to set validateRequest="false" in page directive. OR To enable it at page level instead of complete site and set validateRequest="false" in web.config. When script is injected then It will throw HttpRequestValidationException. A potentially dangerous parameter value was detected from the client (txt=" alert('hello..."). We can handle or capture HttpRequestValidationException to show user friendly message. Second Method: Disable request validation Use the HttpUtility. HtmlEncode method to encode output use HttpUtility. UrlEncode to encode output URLs use validation controls or regular expression I recommend second one. First Method: In web.config set validateRequest = true for complete site. You can disable it for a particular page to set validateRequest="false" in page directive. OR To enable it at page level instead of complete site and set validateRequest="false" in web.config. When script is injected then It will throw HttpRequestValidationException. A potentially dangerous parameter value was detected from the client (txt=" alert('hello..."). We can handle or capture HttpRequestValidationException to show user friendly message. Private Sub Page_Error(ByVal sender As Object, ByVal e As System. EventArgs) Handles MyBase. Error ‘If String. Compare(Server. GetLastError. GetType(). ToString. Trim, "System. Web. HttpRequestValidationException", True) = 0 Then If Server. GetLastError. GetType Is GetType(System. Web. HttpRequestValidationException) Then Server. ClearError() Response. Write("You entered inappropriate characters. Response. Write("Start Over or click Back.") End If End Sub Second Method: Disable request validation Use the HttpUtility. HtmlEncode method to encode output use HttpUtility. UrlEncode to encode output URLs use validation controls or regular expression I recommend second one. Custom ValidationSummary control with multiple validationgroups in asp.net I used same logic as described in my previous post. I made Validate method in custom validationsummary control ChkControl method creates dummy invalid validators and add them with no validationgroup. How to use this custom control: First add it in the toolbox and drag it in your page. Define comma separated multiple validationgroups. Note: it is based on server side validation so set submit button “Causes validation” property false And on button click event, call “customcontrolID. Validate()” instead of “Page.validate()” . It uses null validation group so null validationgroup validators are also validated. Click following to download source code. Don't forget to say thanks if it helps. I made Validate method in custom validationsummary control public void Validate() RemoveAll(); foreach (string str in this. ValidationGroup. ChkControl(str); Page. Validate(); protected void ChkControl(string groupName) foreach (IValidator i in Page. GetValidators(groupName)) Validate(); IsValid) DummyValidator dv = new DummyValidator(i. ErrorMessage); Page. Validators. Add(dv); m_validators. Add(dv); ChkControl method creates dummy invalid validators and add them with no validationgroup. How to use this custom control: First add it in the toolbox and drag it in your page. Define comma separated multiple validationgroups. Note: it is based on server side validation so set submit button “Causes validation” property false And on button click event, call “customcontrolID. Validate()” instead of “Page.validate()” . It uses null validation group so null validationgroup validators are also validated. Click following to download source code. Don't forget to say thanks if it helps. Use multiple validationgroup in Validationsummary in asp.net 2.0 Logic: Use Page. GetValidators("Group") to get the validators in the other group Check for invalid validators, create dummy ivalidators for invalid validators keeping same error message. Add ivalidators in existing page means we are adding a new ivalidator with no validationgroup. Now use Page. Validate(); Example: Suppose there are two textboxes(txt1,txt2) and their requirefieldvalidator belong to different validation group(group1 and group2). Drag a button and set its causesvalidation false. Drag a validationsummary Now code will look like <asp:RequiredFieldValidator ID="req" runat="server" ErrorMessage="1 is required" ControlToValidate="txt1" ValidationGroup="group1" SetFocusOnError="True">* <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="2 is required" ControlToValidate="txt2" ValidationGroup="group2">* <asp:Button ID="Button1" runat="server" CausesValidation="False" onclick="Button1_Click" Text="Button" /> On button click we have to check both validationgroup group1 and group2: To create dummyivalidator Note: Button “CausesValidation” property must be false No validation group must be assigned to button and validationsummary. I made a custom validationsummary control based on this logic. Click here to see it. Use Page. GetValidators("Group") to get the validators in the other group Check for invalid validators, create dummy ivalidators for invalid validators keeping same error message. Add ivalidators in existing page means we are adding a new ivalidator with no validationgroup. Now use Page. Validate(); Example: Suppose there are two textboxes(txt1,txt2) and their requirefieldvalidator belong to different validation group(group1 and group2). Drag a button and set its causesvalidation false. Drag a validationsummary Now code will look like <asp:RequiredFieldValidator ID="req" runat="server" ErrorMessage="1 is required" ControlToValidate="txt1" ValidationGroup="group1" SetFocusOnError="True">* <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="2 is required" ControlToValidate="txt2" ValidationGroup="group2">* <asp:Button ID="Button1" runat="server" CausesValidation="False" onclick="Button1_Click" Text="Button" /> On button click we have to check both validationgroup group1 and group2: protected void Button1_Click(object sender, EventArgs e) AddControl("group1"); AddControl("group2"); Page. Validate(); protected void AddControl(string groupName) foreach (IValidator i in Page. GetValidators(groupName)) Validate(); IsValid) Page. Validators. Add(new DummyValidator(i. ErrorMessage)); To create dummyivalidator internal class DummyValidator : IValidator private string errorMsg; public DummyValidator(string msg) errorMsg = msg; public string ErrorMessage get { return errorMsg; } set { errorMsg = value; } public bool IsValid get { return false; } set { } public void Validate() Note: Button “CausesValidation” property must be false No validation group must be assigned to button and validationsummary. I made a custom validationsummary control based on this logic. Click here to see it. How to call method/properties of one webpage to other using Cross page postback in ASP.NET Our object is to access methods or properties of previous page using Cross page postback feature in asp.net. for example lets create two sample pages in our Web Application: • Source.aspx • Destination.aspx Source.aspx: In .CS Now we have to call this sourcemethod from destination page and after this need to access lblInfo value. For this: Add following in destiantion page We can be completely sure that we have a real CrossPagePostback ONLY IF: Page. PreviousPage is NOT NULL, PreviousPage. IsCrossPagePostback is true This important to check to avoid errors in code. for example lets create two sample pages in our Web Application: • Source.aspx • Destination.aspx Source.aspx: <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" PostBackUrl="~/Destination.aspx" /> In .CS public void SourceMethod() lblInfo. Text = "Your Name is " + txtName. Text; Now we have to call this sourcemethod from destination page and after this need to access lblInfo value. For this: Add following in destiantion page We can be completely sure that we have a real CrossPagePostback ONLY IF: Page. PreviousPage is NOT NULL, PreviousPage. IsCrossPagePostback is true This important to check to avoid errors in code. protected void Page_Load(object sender, EventArgs e) // first check if we had a cross page postback if (Page. PreviousPage != null && (PreviousPage. IsCrossPagePostBack)) Source p = (Source)Page. PreviousPage; SourceMethod(); lbl. Text = ((Label)p. FindControl("lblInfo")). Text; Copy Directory or Move folder in .NET By Default, .NET doesn't provide any inbuilt method to copy directory/sub-directory or move folder as like XCopy command in DOS. Here is the method for this: private void XCopy(String src, String dest,Boolean isOverwrite) DirectoryInfo currentDirectory; currentDirectory = new DirectoryInfo(src); Directory. Exists(dest)) Directory. CreateDirectory(dest); foreach (FileInfo filein in currentDirectory. GetFiles()) filein. CopyTo(System.IO. Path.Combine(dest, filein. Name), true); // To move files uncomment following line // filein. Delete(); foreach (DirectoryInfo dr in currentDirectory. GetDirectories()) XCopy(dr. FullName, Path.Combine(dest, dr. Name), isOverwrite); Create Dynamic Table on Clicking Button in ASP.NET Problem: If we create dynamic table and bind table on one button click then can't be accessed value in another button because of viewstate lose. Solution: create the dynamic table as shown below. The code has been commented to help you understand. VB.NET Step 2: The last piece of code is to determine whether to recreate the controls based on the ViewState[“dynamictable”]. Here’s how it works. The first time the page loads, the LoadViewState() does not execute. The ViewState[“dynamictable”] flag is initialized once the button click occurs. When the postback occurs on the second button click (btnPost), it is then that our code written for overriding the LoadViewState() runs. The base. LoadViewState() instantiates the ViewState object. We then check the value of our ViewState flag, and based on the result, re-create our Table. VB.NET That’s it. Run the code. Enter the number of Rows and Columns to be created and click the Generate button to create the table. Since the table contains textboxes in each cell, manipulate the text inside the table and hit the ‘Cause Postback’ button. Even after the postback, the values of the table control are retained. Note: If multiple controls of the same type are created, remember to create them with the same ID's. Solution: create the dynamic table as shown below. The code has been commented to help you understand. protected void btnGenerate_Click(object sender, EventArgs e) CreateDynamicTable(); private void CreateDynamicTable() PlaceHolder1. Controls. Clear(); // Fetch the number of Rows and Columns for the table // using the properties int tblRows = Rows; int tblCols = Columns; // Create a Table and set its properties Table tbl = new Table(); // Add the table to the placeholder control PlaceHolder1. Controls. Add(tbl); // Now iterate through the table and add your controls for (int i = 0; i < tblRows; i++) TableRow tr = new TableRow(); for (int j = 0; j < tblCols; j++) TableCell tc = new TableCell(); TextBox txtBox = new TextBox(); txtBox. Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j; // Add the control to the TableCell Controls. Add(txtBox); // Add the TableCell to the TableRow Cells. Add(tc); // Add the TableRow to the Table tbl. Rows. Add(tr); // This parameter helps determine in the LoadViewState event, // whether to recreate the dynamic controls or not ViewState["dynamictable"] = true; VB.NET Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As EventArgs) CreateDynamicTable() End Sub Private Sub CreateDynamicTable() PlaceHolder1. Controls. Clear() ' Fetch the number of Rows and Columns for the table ' using the properties Dim tblRows As Integer = Rows Dim tblCols As Integer = Columns ' Create a Table and set its properties Dim tbl As Table = New Table() ' Add the table to the placeholder control PlaceHolder1. Controls. Add(tbl) ' Now iterate through the table and add your controls For i As Integer = 0 To tblRows - 1 Dim tr As TableRow = New TableRow() For j As Integer = 0 To tblCols - 1 Dim tc As TableCell = New TableCell() Dim txtBox As TextBox = New TextBox() txtBox. Text = "RowNo:" & i & " " & "ColumnNo:" & " " & j ' Add the control to the TableCell Controls. Add(txtBox) ' Add the TableCell to the TableRow Cells. Add(tc) Next j ' Add the TableRow to the Table tbl. Rows. Add(tr) Next i ' This parameter helps determine in the LoadViewState event, ' whether to recreate the dynamic controls or not ViewState("dynamictable") = True End Sub Step 2: The last piece of code is to determine whether to recreate the controls based on the ViewState[“dynamictable”]. Here’s how it works. The first time the page loads, the LoadViewState() does not execute. The ViewState[“dynamictable”] flag is initialized once the button click occurs. When the postback occurs on the second button click (btnPost), it is then that our code written for overriding the LoadViewState() runs. The base. LoadViewState() instantiates the ViewState object. We then check the value of our ViewState flag, and based on the result, re-create our Table. // Check the ViewState flag to determine whether to // rebuild your table again protected override void LoadViewState(object earlierState) base. LoadViewState(earlierState); if (ViewState["dynamictable"] == null) CreateDynamicTable(); VB.NET ' Check the ViewState flag to determine whether to ' rebuild your table again Protected Overrides Sub LoadViewState(ByVal earlierState As Object) MyBase. LoadViewState(earlierState) If ViewState("dynamictable") Is Nothing Then CreateDynamicTable() End If End Sub That’s it. Run the code. Enter the number of Rows and Columns to be created and click the Generate button to create the table. Since the table contains textboxes in each cell, manipulate the text inside the table and hit the ‘Cause Postback’ button. Even after the postback, the values of the table control are retained. Note: If multiple controls of the same type are created, remember to create them with the same ID's. Get/Set CheckBoxList values using Javascript in ASP.NET Some times we need CheckBoxList values in Javascript code(For example to select all or clear all in CheckBoxList). Here is described how can we performed client side operations on Asp.net CheckboxList control. Let's assume our webform contains a CheckBoxList named chkTest, as you can see I've put a javascript code when triggers click on checkboxlist. You don't have to... Javascript function called CheckItem contains this script : as you can see with arrayOfCheckBoxLabels[i].innerText property we can get selected list item value. In my code every click on my checklist causes adding checked item value into a hidden area. I used it different purpose. I hope it wouldn't gets harder to understand. In addition . Net renders checkboxlist as a html      </.... you can't get item text and item value properties seperately with Javascript. You can get only item text properties with js. Check/Uncheck all items in a CheckBoxList using ASP.NET and Javascript And in listitem set onclick event onclick="javascript: CheckBoxListSelect (' ',true)" I hope it helps you. Let's assume our webform contains a CheckBoxList named chkTest, as you can see I've put a javascript code when triggers click on checkboxlist. You don't have to... Javascript function called CheckItem contains this script : function CheckItem(checkBoxList) var options = checkBoxList.getElementsByTagName('input'); var arrayOfCheckBoxLabels= checkBoxList.getElementsByTagName("label"); document.getElementById("hdnSutunlar").value=""; for(i=0;i<options.length;i++) var opt = options[i]; if(opt.checked) document.getElementById("hdnSutunlar").value = document.getElementById("hdnSutunlar").value+arrayOfCheckBoxLabels[i].innerText+":"; as you can see with arrayOfCheckBoxLabels[i].innerText property we can get selected list item value. In my code every click on my checklist causes adding checked item value into a hidden area. I used it different purpose. I hope it wouldn't gets harder to understand. In addition . Net renders checkboxlist as a html      </.... you can't get item text and item value properties seperately with Javascript. You can get only item text properties with js. Check/Uncheck all items in a CheckBoxList using ASP.NET and Javascript function CheckBoxListSelect(cbControl, state) var chkBoxList = document.getElementById(cbControl); var chkBoxCount= chkBoxList.getElementsByTagName("input"); for(var i=0;i<chkBoxCount.length;i++) chkBoxCount[i].checked = state; return false; And in listitem set onclick event onclick="javascript: CheckBoxListSelect (' ',true)" I hope it helps you.
1.1 2.1 4.1 5.1 9.1 10.1 11.1 13.1 15.1 17.1 18.1 21.1 22.1 23.1 25.1 26.1 28.1 30.1
Web programlama ile uğraşırken zaman zaman istemci ve sunucu işlemlerini bir arada yapmak isteyebiliriz. Örneğin sunucu tarafından javascript ile client-side işlemler yapmak veya javascript üzerinde sunucu kontrol ve değişkenlerine erişmek gibi. Aslında ASP.NET sunucu kontrollerinin bir HTML karşılığı vardır. Örneğin Label sunucu kontrolü html tarafında span etiketine karşılık gelir. Bu yüzden ASP.NET kontrollerinde HTML olayları veya özelliklerini kullanabilirsiniz. Örneğin bir buton üzerinden gidelim. Butonda OnClientClick="test()" diyerek istemci tarafında tıklama olunca mesaj vermek istiyorum. function test(){ alert("İstemci tarafında tıkladın."); Yukarıdaki kodu sayfanıza ekleyip çalıştırdıktan sonra butona tıklanınca tarayıcı "İstemci tarafında tıkladın." yazan bir pencere açacaktır. Sunucu tarafı da çalışacak orada da sayfaya "Sunucu tarafında tıkladın " yazacaktır. protected void Button1_Click(object sender, EventArgs e) Response.Write("Sunucu tarafında tıkladın"); Tıklama haricinde başka bir olay daha ekleyelim. Fare üzerine gelince "fare üzerine geldi." şeklinde bir mesaj versin. function fareUzerineGeldi() { alert("Fare üzerine geldi."); <asp:Button ID="Button1" onmouseover="fareUzerineGeldi()" OnClientClick="test()" runat="server" Text="Button" onclick="Button1_Click" /> Butonun üzerine farenizi getirdiğinizde "Fare üzerine geldi." diyerek bir mesajla karşılaşıyorsunuz. HTML tarafında aşağıdaki forma dönüşmektedir. Şimdi bir de C# tarafına göz atalım. Sunucudan javascript fonksiyonlarını nasıl çalıştırabiliriz. Aşağıdaki kodlara bir göz atalım. protected void Button1_Click(object sender, EventArgs e) ClientScript.RegisterClientScriptBlock(this.GetType(), "mesaj", " alert('Merhaba') "); Burada sunucu tarafından javascipt kodlarını ekleyerek çalıştırdık.