Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > การรับส่งข้อมูลจาก form ใน Web Content Form ด้วย Method Post หรือ Get ในเวปที่ใช้ Master Page จะต้องเขียน code อย่างไร



 

การรับส่งข้อมูลจาก form ใน Web Content Form ด้วย Method Post หรือ Get ในเวปที่ใช้ Master Page จะต้องเขียน code อย่างไร

 



Topic : 056780



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์




MasterPage1.master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage1.master.cs" Inherits="WebApplicationCShape.MasterPage.MasterPage1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <style type="text/css">
        .style1
        {
            width: 170px;
            background-color: #99FF99;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <table style="width: 100%;">
            <tr>
                <td colspan="2" style="text-align: center; background-color: #99CCFF">
                    &nbsp;
                    &nbsp;
                    &nbsp;
                    Head Master Page</td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;
                    Menu Master Page</td>
                <td>
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
                    </asp:ContentPlaceHolder>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center; background-color: #FFCC99">
                    &nbsp;
                    &nbsp;
                    &nbsp;
                    Foot Master Page</td>
            </tr>
        </table>
    
        
    </div>
    </form>
</body>
</html>


MasterPage1.Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationCShape.MasterPage
{
    public partial class MasterPage1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}


WebContentForm1.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/MasterPage1.Master" AutoEventWireup="true" CodeBehind="WebContentForm1.aspx.cs" Inherits="WebApplicationCShape.MasterPage.WebContentForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" 
    onclick="Button1_Click" />
</asp:Content>


WebContentForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationCShape.MasterPage
{
    public partial class WebContentForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string tb1 = Request.Form["TextBox1"];
            Response.Write("ข้อมูลใน TextBox1 = " + tb1);
        }
    }
}


MasterPage

จาก code ด้านบน ผมลองเขียนเวปโดยใช้ Master Page และเมื่อกดปุ่มแล้วให้่อ่านข้อมูลที่อยู่ใน TextBox มาแสดงที่หน้าเวปด้วย Method Post ด้วยคำสั่ง Request.Form["TextBox1"] ปรากฎว่าไม่สามารถอ่านข้อมูลใน TextBox ไม่ได้ ดังรูป

ผมก็เลยอยากสอบถามว่าผมเขียน code ผิดหรือป่าว หรือว่าในกรณีที่ต้องการรับส่งข้อมูลจาก form ใน Web Content Form ด้วย Method Post หรือ Get ในเวปที่ใช้ Master Page จะต้องเขียน code อย่างไร

ขอบคุณทุกๆ ความคิดเห็นนะครับ



Tag : .NET, Web (ASP.NET), C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-03-02 21:43:34 By : pordee View : 2173 Reply : 4
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

น่าจะใช้ Property ในการส่งน่ะครับ โดย New Class ของ Master Page และทำการส่งค่าผ่าน Parameter ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-03 08:56:13 By : webmaster
 


 

No. 2

Guest


ถ้าเป็นการกดปุ่มแล้ว postback ก็ผ่าน Session หรือ cookie ตามปกติ
แต่ถ้าเป็น javascript ก้อทอรามานกันหน่อยค่ะ

ปกติ event จะเกิดที่ master page แล้วไปที่ content page ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-03 10:01:35 By : สาวเอ๋อ เอ๋อเหรอ เอ๋อมากมาย
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (VB.NET)
Dim mpContentPlaceHolder As ContentPlaceHolder
Dim mpTextBox As TextBox
mpContentPlaceHolder = _
    CType(Master.FindControl("ContentPlaceHolder1"), _
    ContentPlaceHolder)
If Not mpContentPlaceHolder Is Nothing Then
    mpTextBox = CType(mpContentPlaceHolder.FindControl("TextBox1"), _
        TextBox)
    If Not mpTextBox Is Nothing Then
        mpTextBox.Text = "TextBox found!"
    End If
End If

' Gets a reference to a Label control that is not in a 
' ContentPlaceHolder control
Dim mpLabel As Label
mpLabel = CType(Master.FindControl("masterPageLabel"), Label)
If Not mpLabel Is Nothing Then
    Label1.Text = "Master page label = " + mpLabel.Text
End If

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-07-13 15:24:25 By : webmaster
 


 

No. 4



โพสกระทู้ ( 1,348 )
บทความ ( 1 )



สถานะออฟไลน์


ไม่ถนัด C#
แต่มันเขียนแบบนี้เลยไม่ได้เหรอครับ
ไม่ต้องใช้ Request.Form

Code (C#)
string tb1 = TextBox1.Text; 

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-07-13 16:23:48 By : watcharop
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การรับส่งข้อมูลจาก form ใน Web Content Form ด้วย Method Post หรือ Get ในเวปที่ใช้ Master Page จะต้องเขียน code อย่างไร
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่