")受信パラメータ: string a = Request.QueryString["id&quo"/> ")受信パラメータ: string a = Request.QueryString["id&quo">

ホームページ  >  記事  >  バックエンド開発  >  asp.net 値渡しの概要

asp.net 値渡しの概要

怪我咯
怪我咯オリジナル
2017-03-31 11:48:171732ブラウズ

記事はインターネットから収集したもので、ほとんどの内容は asp.net2.0
1 に適しています。新しいウィンドウを開いてパラメータを転送します:
パラメータを転送:
response.write("<script>window) .open ('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="++"')</script>")
パラメータを受け取る:
string a = Request.QueryString["id"];
string b = Request.QueryString["id1"];

2. ボタン
Button1.Attributes.Add("onclick","re​​turnconfirm('confirm?')");
ボタンのダイアログボックスを追加します。 attributes.add( "onclick","if(confirm('are you so?')){return true;}else{return false;}")

3. テーブル内の選択したレコードを削除します
int intEmpID = (int )MyDataGrid.DataKeys[ e.Item.ItemIndex];
string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()

4. テーブル レコードの削除警告

private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)
{
switch( ( LinkBut​​ton)myTableCell.Controls[0];
myDeleteButton.Attributes.Add
("onclick","re​​turnconfirm('このメッセージを削除してもよろしいですか');");
break;
default:
break;
}

}

5. テーブルの行をクリックして別のページにリンクします

private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//Click開くテーブル
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
e.Item.Attributes.Add("onclick","window.open('Default .aspx?id=" + e.Item. Cells[0].Text + "');");
}

itemDataBind イベント
if(e.Item) でテーブルをダブルクリックして別のページに接続します.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
string OrderItemID =e.item.cells[1].Text;
e.item.Attributes.Add("ondblclick", "location.href='../ShippedGrid.aspx?id =" + OrderItemID + "'");
}

テーブルをダブルクリックして新しいページを開きます
if(e.Item.ItemType == ListItemType.項目 ||e.Item.ItemType == ListItemType.AlternatingItem)
{
string OrderItemID =e.item.cells[1].Text;
e.item.Attributes.Add("ondblclick", "open('.. /ShippedGrid.aspx?id=" + OrderItemID + "')");
}

★特記事項: [?id=] を [?id =] にすることはできません
6. テーブルのハイパーリンク列にパラメーターを渡します
NavigateUrl="aaa.aspx?id='<%# DataBinder.Eval(Container.DataItem, "データ フィールド 1")%> '
& name='<%# DataBinder.Eval(Container.DataItem , "データ フィールド 2")%>' />

7. テーブルをクリックして色を変更します
if (e.Item. ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00';
this.style) .color='buttontext';this.style.cursor='default';");
}

DataGridの_ItemDataBoundに書き込む
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType = = ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover" ,"this.style.backgroundColor='#99cc00';
this.style.color='buttontext';this.style.cursor=' default';");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';");
}

8. 日付形式について
日付形式の設定

DataformatString="{0:yyyy-MM-dd} "
itembound イベントにあるはずだと思います
e.items.cell["あなたの列"].text=DateTime.Parse(e. items.cell["あなたの列"].text.ToString("yyyy-MM -dd"))

9. エラーメッセージを取得し、指定したページに移動します
Response.Redirectではなく、Server.Transferを使用します。
e.g

// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError() is HttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");

//Leave残りの HttpUnhandledException 以外の例外は ASP.NET に送られても問題ありません
}

リダイレクトによりポストバックの生成によりエラー情報が失われるため、ページガイダンスはサーバー側で直接実行する必要があるため、エラー情報はエラー処理ページで取得し、それに応じて処理できること

10. Cookie

Cookie.Expires=[DateTime ];
Response.Cookies("UserName").Expires = 0
11 をクリアします。

//カスタマイズされた例外処理クラス
using System;
using System.Diagnostics;

namespace MyAppException
{
/**////


/// システム例外クラス ApplicationException を継承したアプリケーション例外処理クラス。
/// Windows NT/2000 のアプリケーション ログに例外の内容を自動的に記録します
///

public class AppException:System.ApplicationException
{
public AppException()
{
if (ApplicationConfiguration.EventLogEnabled )
LogEvent("不明なエラーが発生しました。");
}

public AppException(string message)
{
LogEvent(message);
}

public AppException(string message,Exception innerException)
{
LogEvent(message ) ;
if (innerException != null)
{
LogEvent(innerException.Message);
}
}

//Logging クラス
using System;
using System.Configuration;
using System.Diagnostics;
using System .IO ;
System.Text を使用;
System.Threading を使用;

名前空間 MyEventLog
{
/**////
/// イベント ロギング クラス、イベント ロギング サポートを提供
///_ {
/**////
/// Win2000/NT イベント ログにエラー メッセージを記録します
/// 記録するテキスト情報
// /

public static void WriteError(String message)
{

WriteLog(TraceLevel.Error, message);
}

/**////
/// Win2000/NT イベント ログに警告情報を記録します
/// 記録するテキスト情報
///

public static void WriteWarning(String message)
{

WriteLog(TraceLevel.Warning, message);
}

/** ////
/// プロンプト情報を Win2000/NT イベント ログに記録します
/// 記録するテキスト情報
// /

public static void WriteInfo(String message)
{
WriteLog(TraceLevel.Info, message);
}
/**////
/// Win2000/NT イベント ログに追跡情報を記録します
/// 記録するテキスト情報
///

public static void WriteTrace(String message)
{

WriteLog(TraceLevel.Verbose, message);
}
/**////
/// イベントログに記録されるテキスト情報の形式を整形します
/// 整形が必要な例外オブジェクト
// /トレース スタック。
///
///

public static String formatException(Exception ex, String catchInfo)
{
StringBuilder strBuilder = new StringBuilder() ;
if (catchInfo != String.Empty)
{
strBuilder.Append(catchInfo).Append("/r/n");
}
strBuilder.Append(ex.Message).Append("/r/n ") .Append(ex.StackTrace);
return strBuilder.ToString();
}

/**////
/ // 実際のイベントログの書き込み方法
/// 記録する情報のレベル(エラー、警告、情報、トレース)。
/// < param name ="messageText">ログに記録するテキスト。
///

private static void WriteLog(TraceLevel level, String messageText)
{

try
{
EventLogEntryType LogEntryType;
スイッチ (レベル)
{
case TraceLevel.Error:
LogEntryType = EventLogEntryType.Error;
ブレーク;
case TraceLevel.Warning:
LogEntryType = EventLogEntryType.Warning;
ブレーク;
case TraceLevel.Info:
LogEntryType = EventLogEntryType.Information;
ブレーク;
case TraceLevel.Verbose:
LogEntryType = EventLogEntryType.SuccessAudit;
ブレーク;
デフォルト:
LogEntryType = EventLogEntryType.SuccessAudit;
ブレーク
}

EventLog eventLog = new EventLog("Application ", ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName );
// イベント ログを書き込みます
eventLog.WriteEntry(messageText, LogEntryType);

}
catch {} // 例外を無視します
}
} //class ApplicationLog
}
12.パネルは水平にスクロールし、自動的に垂直に展開します



13. Enter を押してタブに変換します。