1
저는 ADO.NET 및 SQL에 대한 지식을 테스트 중이며 현재는 기본 작업을 수행하려고합니다. 테이블에서 읽으려는 경우 사용자가 단추를 클릭하면 ApplicationName 열의 값이있는 메시지 상자가 나타납니다.SQL 데이터가있는 메시지 상자를 활성화 할 수 없습니다 - ASP.NET
버튼을 클릭하면 현재 아무 것도하지 않습니다. 어떤 아이디어입니까?
protected void TestSubmit_ServerClick(object sender, EventArgs e) { // Initialize the database connector. SqlConnection connectSQL = new SqlConnection(); // Send the connection string. connectSQL.ConnectionString = @"Data Source = localhost\SQLEXPRESS;" + "Initial Catalog = Inputs; Integrated Security = SSPI"; try { // Setup our command. SqlCommand theCommand = new SqlCommand("SELECT * FROM Inputs", connectSQL); // Write the stored value in the text boxes. connectSQL.Open(); SqlDataReader theReader; theReader = theCommand.ExecuteReader(); theReader.Read(); MessageBox(theReader["ApplicationName"].ToString()); theReader.Close(); connectSQL.Close(); } catch (Exception ee) { MessageBox("Oopsie: " + ee); } private void MessageBox(string msg) { Label lbl = new Label(); lbl.Text = "" + Environment.NewLine + "window.alert('" + msg + "')"; Page.Controls.Add(lbl); }
바로 - 구현의 문제는 당신이 주위에 태그없이 자바 스크립트의 조각을 전송하고 있다는 점이다. 분명히 그것은 스크립트를 실행하지 않을 것입니다. WinForms에서 포스트 백에서이 서버 측을 수행하는 적절한 방법은 RegisterStartupScript 또는 RegisterClientScript – Skeolan
DOH를 사용하여 스크립트를 등록하는 것입니다. 어떤 이유로 든
샘플은 예를
당신은 대신 RegisterClientScriptBlock의 RegisterStartupScript을 사용할 수에 대한 수정했습니다.
편집 : 또는 기존 ASP 방식도 작동해야합니다.
편집기없이이 글을 쓰고 있습니다.
출처
2009-08-13 18:39:32 shahkalpesh
실제로 실행됩니다. 다른 코드에서이 코드를 사용하고 다른 프로젝트에서는 messagebox 함수가 잘 작동합니다. TextBox6이 웹 사이트의 ASP 텍스트 상자입니다
참고 :
는 여기에 내가 정말하고 싶은거야. TestSubmit을 클릭해도 텍스트가 표시되지 않습니다.출처
2009-08-13 18:45:33 Woody