如何在gridview.aspx.cs文件中访问文本框ID [英] How can I access textboxes ID in my gridview.aspx.cs file

查看:103
本文介绍了如何在gridview.aspx.cs文件中访问文本框ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Gridview.aspx.cs文件中添加更新查询但是显示错误,即当前上下文中不存在文本框

如果我添加网格视图和我的注册页面页面,我可以访问我的文本框ID,但我想在另一个页面添加网格视图,以便用户可以在一个页面中添加数据,并将其重定向到我的gridview

希望你有我



i want to add an update query in my Gridview.aspx.cs file but its show error that text boxes is not exist in current context
if i add Grid view and my registration page in same page than i can access my Textboxes ID but i want to add grid view in another page so that user can add data in one page and its redirect to my gridview
Hope you got me

try
        {
            SqlConnection conn = new SqlConnection("Data Source=DESKTOP-KNR6L52;Initial Catalog=FarhanDB;Integrated Security=True");
            conn.Open();
            string insertQuery = "Insert into AddRecord (InternalRecieving,Department,DepartmentType,Orignization,OrignizationType,FileNumber,Date,Subject,FileName,Status)Values(@Fname,@lname,@CNIC,@Gnder,@Mb1,@Mb2,@datebirth,@EmailId,@WD,@Pkge)";

            SqlCommand com = new SqlCommand(insertQuery, conn);
            com.Parameters.AddWithValue("@Fname", InternalRecievingbox.Text);
            com.Parameters.AddWithValue("@lname", Departmentbox.Text);
            com.Parameters.AddWithValue("@CNIC", DpartmnttypeID.Text);
            com.Parameters.AddWithValue("@Gnder", orignizationbox.Text);
            com.Parameters.AddWithValue("@Mb1", orignizationtypebox.Text);
            com.Parameters.AddWithValue("@Mb2", filenumbox.Text);
            com.Parameters.AddWithValue("@datebirth", datebox.Text);
            com.Parameters.AddWithValue("@EmailId", subjctbox.Text);
            com.Parameters.AddWithValue("@WD", filanmebox.Text);
            com.Parameters.AddWithValue("@Pkge", ststbox.Text);
            com.ExecuteNonQuery();
            Response.Write("alert('Your Regestration is Successfull')");
            Response.Redirect("Showtable.aspx");
            //REfershData();
            //Clear();

            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error." + ex.ToString());


        }





我的尝试:



我只尝试了一件事是在同一页面添加网格视图和我的注册页面,而不是我可以访问我的文本框但是我想在gridview页面上重定向它,因为我上面提到

这是我的代码



What I have tried:

I have tried only one thing that is "add Grid view and my registration page in same page than i can access my Textboxes but i want to redirect it on gridview page as i mentioned above"
Here is my code

推荐答案

当你的第二页执行时,第一页就消失了。您尝试访问的TextBox将不再存在。这就是网络的本质 - 无状态。



但是,有一些可能的解决方案,那就是使用CrossPagePostBack和Server.Transfer方法或设置Button服务器控件的PostBackUrl。例如,看看这个:使用C#和VB.Net在ASP.Net中从一个页面到另一个页面查找(访问)控件 [ ^ ]



我建议的另一种方法是公开你想从其他页面访问的控件的公共属性。此属性将保存控件值。
When your second page is executing, the first page is gone. The TextBox that you are trying to access will simply no longer exists. That's the nature of the web - stateless.

However, there are a few possible solutions for that scenario, and that is to use CrossPagePostBack with Server.Transfer method or setting the PostBackUrl of a Button server control. Take a look at this for example: Find (Access) control from one page to another in ASP.Net using C# and VB.Net[^]

Another way that I would recommend is to expose a public properties for controls that you want to access from other pages. This properties will hold the control values.


这篇关于如何在gridview.aspx.cs文件中访问文本框ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆