TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paul Rajs
NA
641
147.2k
in this code how can i get the Text of Button in C#
Jan 31 2018 4:14 AM
hi developers i am using this code it is working fine for me , but i am having a small doubt .
protected
void
Page_Load(
object
sender, EventArgs e)
{
string
query =
string
.Format(
"SELECT roomno from AD_Rooms_Master order by roomno"
);
try
{
DataTable dt = GetData(query);
for
(
int
i = 0; i < dt.Rows.Count; i++)
{
Button btn =
new
Button();
btn.ID =
"btn"
+ (i + 1);
btn.Text = dt.Rows[i][
"roomno"
].ToString();
btn.Click += btnLoadButton_Click;
pnl_btns.Controls.Add(btn);
}
}
catch
(Exception ex)
{
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"Message"
,
"alert('Error occured : "
+ ex.Message.ToString() +
"');"
,
true
);
}
finally
{
//cmd = null;
//conn.Close();
}
}
protected
void
btnLoadButton_Click(
object
sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(
this
.GetType(),
"button"
,
"<script type = 'text/javascript'>alert('Room no "
+ (sender
as
Button).Text +
" selected');</script>"
);
}
could you tell me instead of this how can i get the value by using c# code , because then only i am validate the answer is correct or wrong .
ClientScript.RegisterClientScriptBlock(this.GetType(), "button", "<script type = 'text/javascript'>alert('Room no " + (sender as Button).Text + " selected');</script>");
thanks with
Paul.S
'Man becomes what he thinks about'
Reply
Answers (
1
)
What is the difference between in-proc and out-of-proc?
How to access AccountController From Areas