Can an ASP.Net asp:ControlParameter ControlID be a public shared variable instead of an ASP:label?
We were using an asp:label as a parameter for a DataSource but now want to use a public shared variable instead of the label.
This is the markup of the parameter using the asp:label.
<asp:ControlParameter
ControlID="LabelCheckBoxMonday"
Name="DayOfWeekMonday"
PropertyName="Text"
Type="String" />
We added this public shared variable in the code-behind.
Public Shared blnDayOfWeekMonday As Boolean
We changed the markup for the parameter to this.
<asp:ControlParameter
ControlID="blnDayOfWeekMonday"
Name="DayOfWeekMonday"
PropertyName="Text"
Type="String" />
This is the coding that places values into the variable. The original coding that used to do that for the label is commented out.
Protected Sub ImageButtonInsertDayOfWeekMonday_Click(sender As Object, e As ImageClickEventArgs)
Dim imgTheImageButton As New ImageButton
imgTheImageButton = DetailsView.FindControl("ImageButtonInsertDayOfWeekMonday")
If imgTheImageButton.ImageUrl = "../../Images/checked.png" = True Then
imgTheImageButton.ImageUrl = "../../Images/unchecked.png"
' LabelCheckBoxMonday.Text = False
blnDayOfWeekMonday = False
Else
imgTheImageButton.ImageUrl = "../../Images/checked.png"
' LabelCheckBoxMonday.Text = True
blnDayOfWeekMonday = True
End If
End Sub
All of this is part of the following InsertCommand:
InsertCommand=
"INSERT INTO [TeacherSchedule]
([DayOfWeekMonday],
[DayOfWeekTuesday],
[DayOfWeekWednesday],
[DayOfWeekThursday],
[DayOfWeekFriday],
[DayOfWeekSaturday],
[DayOfWeekSunday],
[StartTime],
[EndTime],
[ClassID],
[TeacherID])
VALUES (@DayOfWeekMonday,
@DayOfWeekTuesday,
@DayOfWeekWednesday,
@DayOfWeekThursday,
@DayOfWeekFriday,
@DayOfWeekSaturday,
@DayOfWeekSunday,
@StartTime,
@EndTime,
@ClassID,
@TeacherID)"
When the web form is running nothing happens after changing it to the public shared variable.
Can you tell me what else I need to do to proceed?
* Update *
Using Marks suggestion I found out how to do an asp:QueryStringParameter but still don't know how to populate it with a value. This is the parameter as an asp:QueryStringParameter
<asp:QueryStringParameter
Name="DayOfWeekMonday"
QueryStringField="QSDayOfWeekMonday" />
How do I populate QSDayOfWeekMonday in the ImageButtonInsertDayOfWeekMonday_Click sub routine?
I tried:
QSDayOfWeekMonday = False
but got a "not declared" error.
* Full markup and code-behind coding *
Another option is to use a Parameter as:
<asp:Parameter Name="DateOfWeekMonthly" />
And in code set the DefaultValue property to the value you want to specify, as in:
DataSourceControl1.Parameters["DateOfWeekMonthly"].DefaultValue = someVariable;
This has worked for me.
You could establish this event in the Selecting event that fires; this event fires before the select happens; therefore, you can establish the boolean value. I believe here, you can add it to the collection of values defined in the event argument.